在下面的代码中,为什么 int
有效而 float
无效?结果如下。
voidptr.c :
#include <stdio.h>
typedef void* (*Fn) ();
int Fun()
{
return 5;
}
float fFun()
{
return 5.0;
}
void callfun(Fn f)
{
printf ("%d \n", f());
}
void callffun(Fn f)
{
printf ("%f \n", f());
}
int main()
{
callfun(Fun); // works
callffun(fFun); // --> doesnt work ??
printf ("%f", fFun()); // works
return 0;
}
输出:
5
0.000000
5.000000
最佳答案
你在欺骗编译器。结果不可预测。
关于c - 为什么返回 float 的函数不适用于 void* 回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15776839/