"Peter Federighi" <[email protected]> wrote in message news:[email protected]... > Is there a way to do it without removing handler() from the class? When I > try > compiling, I get: Error: cannot implicitly convert expression > (&this.handler) > of type void delegate(int signal) to void C function(int).
Yes, but it requires some nasty code. (Not tested on anything except windows) http://yebblies.com/thunk.d (Also not tested) import yebblies.thunk.d; import std.c.linux.linux; import std.stdio; class FOO { this() { th = thunk!"C"(&handler); sa.sa_handler = th.ptr; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction(SIGALRM, &sa, null); } ~this() { sa.sa_handler = SIG_DFL; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction(SIGALRM, &sa, null); } private: sigaction_t sa; typeof(thunk!"C"(&handler)) th; void handler(int signal) { writeln("Got an alarm signal."); } } It basically gets around the restriction by writing some code into memory that passes the delegate params in unused registers. I don't even know if the page allocation code works on anything except windows. Daniel
