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 &bar;
}

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

Reply via email to