Comment #0 by bearophile_hugs — 2011-03-27T14:42:14Z
A little D2 program:
int[] foo() {
return [];
}
int[] bar() {
return null;
}
void main() {}
The asm of the two functions, compiling it with DMD 2.052:
dmd -O -release -inline test2.d
_D5test23fooFZAi comdat
L0: push EAX
mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
push 0
push EAX
call near ptr __d_arrayliteralT
mov EDX,EAX
add ESP,8
pop ECX
xor EAX,EAX
ret
_D5test23barFZAi comdat
xor EAX,EAX
xor EDX,EDX
ret
I am not sure, but I think it's better to compile foo() to the same assembly as bar().
Comment #1 by dlang-bugzilla — 2011-04-01T19:03:12Z
No!
Often it is extremely useful to distinguish an empty array from a null one.
(You do that with "is null").
"Fixing" this will break a lot of my code.
Comment #2 by dlang-bugzilla — 2011-04-01T19:08:43Z