Read Function Definitions in C

I am a Java developer, and for some reason I am learning C at the moment. The fact is that I have problems reading function definitions. Could you give me a hint with this, for example:

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

Thanks guys!

+6
c function definition
source share
3 answers

You must study the rule from right to left . This page contains good examples.

signal is a function that takes as an argument:

  • integer
  • pointer to a function that takes an int and returns nothing

and returns a pointer to a function that takes an int and returns nothing.

+4
source share

func is a pointer to a function that takes an int and returns void.

signal is a function that takes an int and a pointer as func and returns a pointer as func.

That is: you indicate which signal handler (func) is associated with the signal (sig), and the function returns a signal handler (previous), which you can store somewhere.

+2
source share

Example "cdecl" in action. I think its available for Linux or source can be downloaded and created.

 cdecl> explain char *(*fptab[])() declare fptab as array of pointer to function returning pointer to char cdecl> 
+2
source share

All Articles