[英]c function declaration explanation on argument with type “void(*fcn)(void*)”
I encountered the following line as a C function declaration. 我遇到了以下一行作为C函数的声明。 I'm confused by the type of the first argument passed in. Can anyone explain how to understand the type of the first argument?
我对传入的第一个参数的类型感到困惑。有人可以解释如何理解第一个参数的类型吗?
int clone(void (*fcn) (void *) , void *arg, void *stack)
void (*fcn) (void *)
从内到外读取类型: fcn
是指向函数的指针,该函数采用void *
参数,但不返回任何内容( void
)。
Use "Spiral Rule" : 使用“螺旋规则” :
+------+
| +--+ |
| ^ | |
void (*fcn ) (void *)
^ ^ | |
| +----+ |
+----------+
So, 所以,
fcn
is a pointer to fcn
是指向 void *
as an argument void *
作为参数的函数 void
(nothing) void
(什么都没有) After a few editing (to remove the names of variables) cdecl gave the answer : 经过几次编辑(删除变量名称)后, cdecl给出了答案 :
declare clone as function (pointer to function (pointer to void) returning void, pointer to void, pointer to void) returning int
将clone声明为函数(指向函数的指针(指向void的指针),返回void,指向void的指针,指向void的指针)返回int
Or, you can test only the first argument and get it's type: pointer to function of pointer to void, returning void. 或者,您可以仅测试第一个参数并获取其类型:指向void的函数的指针,返回void。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.