c - 为什么返回 float 的函数不适用于 void* 回调?

标签 c callback

在下面的代码中,为什么 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/

相关文章:

C 通过主机名获取ip

javascript - 回调异常[TypeError : listener must be a function]

ruby-on-rails - 回调是否停止 rails 中的操作

javascript - "for"循环中的 Ajax 调用跳过奇数/偶数迭代

node.js:来自 child_process 的 console.log

c - jni 回调适用于 java 类型,但不适用于 c 类型

在C中的特定地址构造数组

c - 在像 touch.c 这样的 FreeBSD 代码中,以美元符号作为第一个和最后一个字符的 RCSID 是什么意思?

C 客户端-服务器应用程序和 Linux 上的电池节省

C嵌套结构指针问题