On Monday, 14 November 2022 at 21:00:38 UTC, matheus wrote:
void[] getFoo(){
    writeln(cast(int[])bar);
    auto foo = getFoo();
    writeln(foo);

Prints:

[1, 0]
[2, 0, 0, 0, 0, 0, 0, 0]

Looking through godbolt.org the ASM generated with both

So why the array generated from getFoo() is 4 times bigger than the other?

It isn't. You're casting one to int[] and not casting the other, leaving it as void[], which writeln will interpret as just raw bytes.

Since an int is 4x bigger than a byte, casting it to int shows 1/4 the number of ints.

But the actual array is the same.

Reply via email to