www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5788] New: Return [] array

reply d-bugmail puremagic.com writes:
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



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: -------
Mar 27 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5788


Vladimir <thecybershadow gmail.com> changed:

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



---
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: -------
Apr 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5788




---
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: -------
Apr 01 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5788




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: -------
Jul 03 2013