从标准的信号库C的声明 [英] C declaration from standard signal Library
问题描述
所以,有人可以解释这是应该做的:
So can someone explain what this is supposed to do:
void (*signal(int sig, void (*func)(int)) ) (int);
这是标准的信号库中提取的定义。
It is a definition taken from the standard signal library.
推荐答案
启动名为:
signal
往右尽可能您可以:
Go right as far as you can:
signal(int sig, void (*func)(int))
您的参数组合列表,所以它的服用2个参数的函数:一个 INT
名为 SIG
和命名的函数指针 FUNC
(你可以分析它在以后的方法相同)。
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).
然后你打另一个rightparen,让你去左边:
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)
我们再次有带括号的表,所以信号
返回一个指针函数,它接受一个 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)
这样的功能信号
返回函数指针服用 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. :)
这篇关于从标准的信号库C的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!