Const ref and rvalues again...
Jonathan M Davis
jmdavisProg at gmx.com
Sun Nov 11 13:18:26 PST 2012
On Sunday, November 11, 2012 12:10:59 David Nadlinger wrote:
> 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();
> }
> ---
That did it. And if scope is removed, it works again. I clearly don't get the
low level stuff though, since it's just plain bizarre to me that the previous
example didn't do it.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list