Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested function pointer declarations [duplicate]

Tags:

c

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

like image 384
Paul CyberCitizen Avatar asked Aug 09 '26 08:08

Paul CyberCitizen


1 Answers

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;
}
like image 93
beothunder Avatar answered Aug 10 '26 22:08

beothunder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!