www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2075] New: Spec does not specify how array literals are stored.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2075

           Summary: Spec does not specify how array literals are stored.
           Product: D
           Version: 1.029
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: spec
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: tomas famolsen.dk


It seems DMD currently allocates all array literals on the GC heap. The spec
however does not state that this is the required behaviour, and frankly I think
it's a bad idea not being able to get a stack array without instead declaring a
static array temporary explicitly.


-- 
May 06 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2075





------- Comment #1 from tomas famolsen.dk  2008-05-06 15:04 -------
Code to see for yourself:

extern(C) int printf(char*, ...);

int[] func()
{
    int[] arr = [1,2,3];
    return arr;
}

void main()
{
    int stack;
    int[] arr = func();
    printf("%d %d %d\n", arr[0], arr[1], arr[2]);
    printf("stack: %p\nwhere? %p\n", &stack, arr.ptr);
    int[] arr2 = [1,2,3,4,5];
    printf("where? %p\n", arr2.ptr);
}


-- 
May 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2075


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla digitalmars.com  2008-05-22 05:05 -------
Fixed dmd 1.030 and 2.014


-- 
May 22 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2075


brunodomedeiros+bugz gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brunodomedeiros+bugz gmail.c
                   |                            |om




------- Comment #3 from brunodomedeiros+bugz gmail.com  2008-05-28 16:13 -------
It might also be good to state that each array literal evaluation causes a new
array to be allocated. (Unlike string literals for example)


-- 
May 28 2008