c - 用指针引用函数

标签 c

(int ( * ) (void*, void*))(numeric ? numcmp : strcmp));

numcmp 和 strcmp 是带有两个参数的函数。

我明白条件运算符在做什么。这很简单。

我可以推断这将计算为 numcmp(void*, void*) 或 strcmp(void*, void*),但我不明白为什么?特别是: int (*),让我感到困惑。

最佳答案

表达式 (int ( * ) (void*, void*)) 只是一个函数指针的转换,带有两个返回 int 的 void* 参数。对于其他转换,语法类似于没有变量名的变量声明。然后根据 bool 开关决定要转换的函数。

关于c - 用指针引用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44091489/

相关文章:

c - GCC 和 Visual Studio(32 位 Controller )中结构大小的差异

c - printf: 不能使用 %*c 打印少于 1 个字符

c - 无法在 C 中使用 qsort 对 dirent 进行排序

c - 在 C 中执行 OOP 时模拟 'this' 指针的优雅方法?

c - 海合会: "warning: assignment from incompatible pointer type"

c - 将数组增加到一定数量

无法在c中使用fprintf将数据保存在txt文件中

c - 如何在不使用if函数的情况下重新排列数字?

c - 图结构深拷贝

c - 具有许多数字的随机数组出现错误