Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading function definitions in C

I'm a Java dev, and for some reason I'm studying C at the moment. The thing is I'm having some trouble reading function definitions. Could you give me a hint with this one for instance:

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

Thanks guys!

like image 799
Albus Dumbledore Avatar asked Feb 11 '11 12:02

Albus Dumbledore


2 Answers

You should learn the right-to-left rule. This page contains good examples.

signal is a function taking as arguments:

  • an integer
  • a pointer to function taking int and returning nothing

and returning a pointer to a funcction taking int and returning nothing.

like image 152
Benoit Avatar answered Sep 19 '22 13:09

Benoit


An example of 'cdecl' in action. I think its available for Linux or source can be downloaded & built.

cdecl> explain char *(*fptab[])()
declare fptab as array of pointer to function returning pointer to char
cdecl> 
like image 22
David Victor Avatar answered Sep 22 '22 13:09

David Victor