I found this declaration in the APUE book in the chapter on signals:
void (*signal(int signo, void (*func)(int)))(int);
I don't fully understand the syntax. The declaration of (*func) is syntactically what I expect for a function parameter/pointer. I don't understand the syntax where "signal" is declared, and the trailing (int). I was wondering if someone could clarify this. -Thanks
The function signal returns a pointer to a function of type void (int), and has two arguments: an int and a pointer to a function of type void (int).
So something like this should work
void foo(int);
void (*signal(int signo, void (*func)(int)))(int)
{
return func;
}
int main(int argc, char *argv[])
{
signal(42, foo);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With