Jarrett Billingsley schrieb:
"Xinok" <xnknet@gmail.com> wrote in message 
news:fgg9q8$jlr$1@digitalmars.com...
  
It seems that variables that are used by a nested function are allocated 
on the heap rather than the stack. This was my test code:

void delegate() foo(){
int v = 60;
int c = 35;
writefln(&c);
writefln(&v);
return {writefln(&v);};
}

void main(){
void delegate() one = foo();
one();
}

Prints:
12FF18
8B2FF4
8B2FF4

The address of 'v' doesn't change. What you do notice is the great 
difference of the memory addresses between int v and int c, which suggests 
that 'v' is allocated on the heap rather than the stack.

    

Hm.  Don't have a D2 compiler with me -- could you run the following and 
tell me what it prints?

void main()
{
    int v, c;

    void foo()
    {
        writefln(&c);
    }

    writefln(&v);
    writefln(&c);
}

I'm wondering if the compiler is smart enough not to allocate variables on 
the heap if it doesn't have to.  (I'm not returning foo.) 
  

Prints:
13FF28
13FF2C

...whatever that means...


~Extrawurst