How to catch a signal

W.Boeke w.boeke at upcmail.nl
Sat Nov 9 13:57:38 UTC 2019


On Saturday, 9 November 2019 at 12:56:52 UTC, Dennis wrote:
>
> Put an ampersand before the function to get its address:
>>   signal.signal(SIGWINCH,cast(void function(int)) &set_winch);
>
> In C you can omit the & when taking a function address, but 
> when you do that in D it tries to call the function and cast 
> the return value of the function instead.

Bingo! That worked. The modified code is:

int winch;
extern(C) void set_winch(int sig) nothrow @nogc @system {
   enum SIGWINCH = 28;
   signal.signal(SIGWINCH,&set_winch);
   winch = sig;
}

Wouter


More information about the Digitalmars-d-learn mailing list