11/11/2012 2:08 PM, Jonathan M Davis пишет:
On Sunday, November 11, 2012 13:36:05 Dmitry Olshansky wrote:
Nope. It's just that the stack is intact and contains: hello and goodbye
one after another. Without optimizations { } scope doesn't mean reuse
stack space.

Now if play with stack a bit, for me the next one prints:
­-²↑

import std.stdio;

void delegate() global;

void foo(scope void delegate() del)
{
      global = del;
}


void f()
{
      {
          char[5] bar = "hello";
          foo((){writeln(bar);});
      }
}

void main()
{
      char[7] baz = "goodbye";
      f();

      global();
}

It still prints "hello", even with full optimations turned on.

I tried with and without optimizations. I get garbage as expected.

So, it must be
allocating a closure in spite of scope. So, it looks to me like scope is just
completely ignored and does absolutely nothing at this point, unless I'm just
completely missing something here.

Something must be screwed up. I dunno what, I use near-latest DMD from github and Win32 binaries. For good measure try making stack variables larger if you are on 64bit. Drop in a couple of calls to writeln before and after calling 'f' it should scramble the stack.

--
Dmitry Olshansky

Reply via email to