C declaration from standard signal Library

Start with the name:

signal

Go right as far as you can:

signal(int sig, void (*func)(int))

You have a parenthesized list of parameters, so it’s a function taking 2 parameters: an int named sig and a function pointer named func (you can analyze it in the same way later).

Then you hit another rightparen, so you go left:

*signal(int sig, void (*func)(int))

So the function signal returns a pointer to… something. Let’s take down the parenthesis and go right again, since we can:

(*signal(int sig, void (*func)(int)) ) (int)

We have again a parenthesized list of arguments, so signal returns a pointer to function which takes an int as an only argument. Then go left again:

void (*signal(int sig, void (*func)(int)) ) (int)

Thus the function signal returns the pointer to function taking int and returning void.

Yes, this language is weird, but at least it’s consistent. 🙂

Leave a Comment