首页 > 学院 > 开发设计 > 正文

<The C programming language> 5.11 函数指针 “函数名称就是函数的地址?”

2019-11-08 02:28:09
字体:
来源:转载
供稿:网友
qsort1((void **) lineptr, 0, nlines - 1, (int (*)(void *, void *))(numeric ? numcmp : strcmp));

Wedit output window build: Sun Feb 19 10:26:10 2017Error h:/c_workcarbin/mytest.c: 26  Operands of ?: have illegal types 'pointer to int function(pointer to char,pointer to char)' and 'pointer to int function(pointer to char,pointer to char)'Compilation + link time:0.0 sec, Return code: 1

编译环境:LCC-WIN32

(1)按如下定义后,用fun1,fun2去替换numcmp,strcmp可以编译通过。

//	int (*fun1)(void *,void*) = (int (*)(void *, void *)) &numcmp;//	int (*fun2)(void *,void*) = (int (*)(void *, void *)) &strcmp;(2)或者,将强制类型转换分别对numcmp,strcmp做一遍,也可以通过编译。

qsort1((void **) lineptr, 0, nlines - 1, (int (*)(void *, void *))(numeric ? (int (*)(void *, void *))numcmp : (int (*)(void *, void *))strcmp));


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表