[Issue 1648] New: Casting a function literal to void* swallows the function or segfaults

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Nov 8 14:34:11 PST 2007


"Christopher Wright" <dhasenan at gmail.com> wrote in message 
news:fgve35$eet$1 at digitalmars.com...
>
> (delegate*).sizeof == (void*).sizeof
> The example casted the address of the delegate to void*.
>

Ah, looking at your code again, I realize that I was wrong in reading it. 
Now I notice that it's just plain wrong:

void send (void delegate () func) {
    _funcptr = cast(void*)&func;
}

This is entirely wrong.  You're storing the address of a local variable in a 
class member, and then trying to call that in another function.  A quality 
compiler would give a warning/error on this, as it's an escaping reference 
to a local variable. 




More information about the Digitalmars-d-bugs mailing list