这是一个空指针吗?铸件?它在做什么?
我是 C 语言和指针的新手,我对这个函数声明感到困惑:
void someFunction(int (*)(const void *, const void *));
任何人都可以用外行的术语解释它的作用以及它是如何工作的吗?
I am new to the C language and pointers and I am confused by this function declaration:
void someFunction(int (*)(const void *, const void *));
Can anyone explain in layman's terms what this does and how it works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它是一个函数的原型,它需要:
作为参数,并返回 <代码>无效。
It's the prototype of a function that takes:
as an argument, and returns
void
.它声明一个函数,该函数接受另一个函数作为其参数,并且不返回任何内容。另一个函数将被声明为
,并且您将像这样调用 somefunction() :
It declares a function, which takes another function as its argument, and returns nothing. The other function would be declared as
and you would call somefunction() like this:
它是一个具有单个参数的函数。该参数是一个指向函数的指针,该函数返回 int 并将这两个 void 指针指向常量数据参数。
It's a function that has a single parameter. That parameter is a pointer to a function that returns an int and takes those two void pointers to constant data parameters.
这是一个函数的声明,它采用函数指针作为其参数。最基本的形式是这样的:
其中
argument_type
是int (*)(const void *, const void *)
,可以将其描述为“指针”一个带有两个 const void * 参数并返回 int 的函数”。即具有以下声明的任何函数:通过示例说明:
This is the declaration of a function which takes a function pointer as its argument. In its most basic form, it looks like this:
Where
argument_type
isint (*)(const void *, const void *)
, which can be described as a "pointer to a function that takes two const void * arguments, and returns an int". i.e. any function that has the following declaration:To illustrate by example:
检查此项在处理复杂声明时非常有帮助。
Check this very helpful when dealing with complex declarations.