[Issue 1648] Casting a function literal to void* swallows the function or segfaults
Derek Parnell
derek at nomail.afraid.org
Thu Nov 8 16:02:01 PST 2007
On Fri, 9 Nov 2007 10:48:15 +1100, Derek Parnell wrote:
> I made a slight change to the code and it seems to work.
Another change to make it clearer to read...
------------
import std.stdio;
class Foo {
alias void delegate() dg;
private dg* _funcptr;
private dg _func;
void send (dg* func) {
_funcptr = func;
}
void send (dg func) {
_func = func;
_funcptr = &_func;
}
void execute () {
(*_funcptr)();
}
}
void main () {
Foo foo = new Foo();
auto func = { writefln("greetings"); };
foo.send(&func);
foo.execute();
foo.send({ writefln("this one is typed"); });
foo.execute();
}
----------
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
9/11/2007 10:59:25 AM
More information about the Digitalmars-d-bugs
mailing list