开发者

Reading function definitions in C

开发者 https://www.devze.com 2023-02-10 11:31 出处:网络
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 y开发者_高级运维ou give me a hint with this one for instan

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 y开发者_高级运维ou give me a hint with this one for instance:

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

Thanks guys!


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.


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> 


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

signal is a function which takes an int and a pointer like func and returns a pointer like func.

That is: you specify which signal handler (func) associate to the signal (sig), and the function returns a signal handler (the previous one) which you can store somewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消