int * (*) 的类型 (int * , int * (*)())
int * (*) (int * , int * (*)())
我想知道它是什么类型? ,有人可以给出使用这种类型的声明的示例吗?
任何帮助都会很棒。
谢谢。
int * (*) (int * , int * (*)())
I'd like to know what type is it ? , can someone give an example of a declaration using this type.
any help would be great.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它是一个指向返回
int*
并接受int*
的函数的指针,也是一个指向返回int*
的函数的指针(并接受未定义数量的参数) ;见评论)。一些示例(看起来不太好,它只是被构造为包含提到的声明):
It is a pointer to function that returns
int*
and acceptsint*
and pointer to function that returnsint*
(and accepts undefined number of parameters; see comments).Some example (does not look very nice, it is just constructed to contain the mentioned declaration):
cdecl
是你的朋友:cdecl
is your friend:嗯...根据 cdecl.org 这是一个语法错误 - 让我尝试一下
()() - 函数指针
int ()() - 指向无参数函数的指针,返回指向 int 的指针
所以:
它是一个函数指针,有两个参数,第一个参数是指向 int 的指针,另一个是无参数返回 int 指针的函数指针,其返回指针至-int。
编辑:我在该网站中使用的 C 声明 - 我没有放入返回的变量名称
:将 x 声明为指向函数的指针(指向 int 的指针、指向返回指向 int 的指针的函数)返回指向 int 的指针
Hmmm... according to cdecl.org that was a syntax error - let me try
()() - a pointer to function
int ()() - pointer to function with no parameters, returning pointer to int
So:
It's a function-pointer which has the two parameters which the first parameter is a pointer to int and the other is pointer-to-function-with-no-parameters-returning-pointer-to-int,and its-returning-pointer-to-int.
Edit: The C declaration that I used in that website - I did not put in a variable name as in
which returned: declare x as pointer to function (pointer to int, pointer to function returning pointer to int) returning pointer to int
有一种称为“左右规则”的技术可以帮助您破译此类复杂的声明。该规则的工作原理是用英语关键字替换声明中出现的属性。然后,当您将关键字放在一起时,构建的句子将描述声明。
以下是您应该使用的属性和关键字:
现在这里是“右左规则”:
下面是一些示例:
标识符是 n。右侧的属性是
[10]
,因此使用关键字“array of 10”。接下来,您将到达数据类型int
。因此,n 是一个“10 个整数的数组”。
标识符是n。右侧的属性是
[10]
,因此使用关键字“array of 10”。向左看,属性是*
,所以使用关键字“pointer to”。没有更多的属性了。剩下的就是数据类型,即int
。将关键字放在一起可以得到:n 是一个“由 10 个整数指针组成的数组”。
标识符是pf。 pf 右侧没有紧邻的属性。 pf 左边是
*
。所以第一个关键字是“指向的指针”。接下来回到右边,属性是()
。这意味着下一个关键字是“返回的函数”。现在回到左边的数据类型int
。将关键字放在一起可以得到:pf 是“指向返回 int 的函数的指针”
pf 是标识符。 pf 右边没有属性。左边是
*
,所以第一个关键字是“pointer to”。回到右边是()
,所以下一个关键字是“返回的函数”。回到左边是*
,所以下一个关键字是“pointer to”。接下来,到达 int 数据类型:pf 是“指向返回 int 指针的函数的指针”。
下一个示例与上一个示例类似,但这次 pf 函数有一些参数。参数为
int *x
和int *(*y)()
。您应该能够根据到目前为止的所有内容来描述每个论点。一旦你这样做了,你将能够描述整个事情:pf 是一个指向函数的指针,该函数返回一个指向 int 的指针。 pf 有两个参数。第一个参数 x 是一个指向 int 的指针。第二个参数 y 是一个指向函数的指针,该函数返回一个指向 int 的指针。
There's a technique called the "right-left rule" that can help you decipher complex declarations like these. The rule works by substituting english keywords for the attributes that appear in the declaration. Then when you put the keywords together, the sentence constructed will describe the declaration.
Here's the attributes and the keywords you should use:
Now here's the "right-left rule":
Here's some examples:
The identifier is n. The attribute on the right is
[10]
, so use the keyword "array of 10". Next you reach the data typeint
. So,n is an "array of 10 integers".
The identifier is n. The attribute on the right is
[10]
, so use the keyword "array of 10". Look to the left and the attribute is*
so use keyword "pointer to". There's no more attributes. All that is left is the data type, which isint
. Put the keywords together to get:n is an "array of 10 pointers to integers".
The identifier is pf. There's no attribute immediately to the right of pf. To the left of pf is
*
. So the first keyword is "pointer to". Next, go back to the right and the attribute is()
. That means the next keyword is "function that returns". Now go back to the left to the data typeint
. Put the keywords together to get:pf is a "pointer to a function that returns an int"
pf is the identifier. There's no attributes to the right of pf. To the left is
*
, so the first keyword is "pointer to". Back to the right is()
, so the next keyword is "function that returns". Back to the left is*
, so the next keyword is "pointer to". Next, reach theint
data type:pf is a "pointer to a function that returns a pointer to an int".
This next example is just like the previous one, but this time there's some arguments to the pf function. The arguments are
int *x
andint *(*y)()
. You should be able to describe each of these arguments based on the everything up until now. And once you do that you'll be able to describe the whole thing:pf is a pointer to a function that returns a pointer to an int. pf takes two arguments. The first argument x is a pointer to an int. The second argument y is a pointer to a function that returns a pointer to an int.
您可以将
foo
放入该类型中。You can put
foo
in that type.这样的声明确实有用!考虑标准 C 库的信号函数:
信号手册页解释说它相当于以下 typedef 版本:
一个接受两个参数、int 和 sig_t 函数的函数,并返回旧的 sig 函数。
Such declaration are really used !. Consider the signal function of the standard C library:
the signal man page explains it is equivalent to the following typedef'd version:
A function that takes two args, and int and a sig_t function, and that returns the old sig function.