Please explain this type signature : void (*signal(int signo, void *(func)(int)))(int)
相关问题
- Multiple sockets for clients to connect to
- Keeping track of variable instances
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- How to get the maximum of more than 2 numbers in V
C declarations need to be read from the inside out. The tricky part with complex function declarations is figuring out which is the innermost declarator (where to start). Its generally the first identifier that is not a type identifier. So in this case:
the declarator is
signal
. Within the parenthesis, suffixes are higher precedence than prefixes, sosignal
is a function taking two args (the(int signo, void *(func)(int))
part), that returns a pointer (the prefix*
) to a function taking a single int arg (the(int)
on the end), and returningvoid
The type signature of the
signal
function is a bit more clear when a typedef is used for the function pointers that are passed around:sighandler_t
is a pointer to a function that takes anint
parameter and returns nothing. Thesignal
function takes such a function pointer as its second parameter. It also returns a function pointer of that type.