首页 > 解决方案 > 如何在objective-c中正确地printf float (*)()?

问题描述

我在控制台上尝试了这两行代码printf,但是,在 Objective-C 中,我收到一条错误消息:format specifies type 'double' but the argument has type 'float (*)()'

如何正确地使它在 Obj-C 中工作?

SomeValue = (float (*)())dlsym(someServices, "someMethod");
printf("%f\n", someValue);

提前致谢!

标签: objective-c

解决方案


someValue在您的代码中是函数指针,而不是从相应函数返回的值。如果您需要打印从该函数返回的值,只需调用它:

printf("%f\n", someValue());
//                      ^^

不言而喻,您必须检查NULL来自dlsym.


推荐阅读