escaping addresses of ref parameters - not

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Feb 8 22:12:18 PST 2009


Denis Koroskin wrote:
> I agree. It also grants safe way to pass temporaries:
> 
> int bar();
> int* gi;
> void foo(ref int i)
> {      gi = &i;
> }
> 
> foo(bar()); // unsafe
> 

Well rvalues still shouldn't bind to temporaries because I want to allow 
a function to return by ref a ref parameter:

ref int foo(ref int i)
{
     if (i == 0) ++i;
     return i;
}

Binding an rvalue to a ref would essentially pass a zombie out of foo.


Andrei



More information about the Digitalmars-d mailing list