Const ref and rvalues again...

David Nadlinger see at klickverbot.at
Sun Nov 11 03:10:59 PST 2012


On Sunday, 11 November 2012 at 10:09:17 UTC, Jonathan M Davis 
wrote:
> It still prints "hello", even with full optimations turned on. 
> 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.

Try this:

---
import std.stdio;

void delegate() global;

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


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

void smashStack() {
     uint[1000] dummy = 0xbadcab1e;
     asm { nop; }
}

void main()
{
      char[7] baz = "goodbye";
      f();
      smashStack();
      global();
}
---

David


More information about the Digitalmars-d mailing list