Re: Delegates with stackpointers

2018-09-29 Thread bauss via Digitalmars-d-learn

On Saturday, 29 September 2018 at 06:01:50 UTC, Ritchie wrote:
How does a delegate with a stackpointer work? e.g. in this 
example:


https://run.dlang.io/is/XviMSl

Does the second call to foo not overwrite the stack of the 
first call and thereby the data pointed to by bar1? How is that 
data preserved?


In this case "a" will not live on the stack of "foo".

This can be proved by:

Shows all variables in "sequence: (Because "a" is  not used 
within the delegate.)


https://run.dlang.io/is/mwopBi

Shows only "b" and "c" in sequence:

https://run.dlang.io/is/c0rpO8


Re: Delegates with stackpointers

2018-09-29 Thread Alex via Digitalmars-d-learn

On Saturday, 29 September 2018 at 06:01:50 UTC, Ritchie wrote:
How does a delegate with a stackpointer work? e.g. in this 
example:


https://run.dlang.io/is/XviMSl

Does the second call to foo not overwrite the stack of the 
first call and thereby the data pointed to by bar1? How is that 
data preserved?


Why should a call to foo overwrite something? Aren't these two 
foos equivalent from this point of view?


´´´
DelegateT foo1() {
int a = 0;
void bar() {
a++;
writeln(a);
}
return 
}

auto foo2()
{
struct S
{
int a;
void opCall()
{
a++;
writeln(a);
}
}
return S.init;
}
´´´


Delegates with stackpointers

2018-09-29 Thread Ritchie via Digitalmars-d-learn
How does a delegate with a stackpointer work? e.g. in this 
example:


https://run.dlang.io/is/XviMSl

Does the second call to foo not overwrite the stack of the first 
call and thereby the data pointed to by bar1? How is that data 
preserved?