null Vs [] return arrays
Kagamin
spam at here.lot
Sun Mar 27 11:05:54 PDT 2011
bearophile Wrote:
> I have compiled this little D2 program:
>
>
> int[] foo() {
> return [];
> }
> int[] bar() {
> return null;
> }
> void main() {}
>
>
>
> Using DMD 2.052, dmd -O -release -inline test2.d
>
> This is the asm of the two functions:
>
> _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
>
> Is this expected and desired? Isn't it better to compile the foo() as bar()?
>
> Bye,
> bearophile
[] is not null, it's an array of 0 elements, what is done exactly.
edx points to the allocated array.
More information about the Digitalmars-d-learn
mailing list