Thread overview
[Issue 5788] New: Return [] array
Apr 02, 2011
Vladimir
Apr 02, 2011
Vladimir
March 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5788

           Summary: Return [] array
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2011-03-27 14:42:14 PDT ---
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().

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5788


Vladimir <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com


--- Comment #1 from Vladimir <thecybershadow@gmail.com> 2011-04-01 19:03:12 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5788



--- Comment #2 from Vladimir <thecybershadow@gmail.com> 2011-04-01 19:08:43 PDT ---
Erm, never mind, [] still creates a null array. I just remembered I had to do something more tricky in my code to make empty non-null arrays.

https://github.com/CyberShadow/RABCDAsm/blob/cecff913/abcfile.d#L1094

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5788



--- Comment #3 from bearophile_hugs@eml.cc 2013-07-03 11:19:34 PDT ---
currently this code:

void main() {
    int[] emptyArray = [];
}



Produces:

__Dmain comdat
L0:     push    EAX
        mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
        push    0
        push    EAX
        call    near ptr __d_arrayliteralTX
        add ESP,8
        xor EAX,EAX
        pop ECX
        ret

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------