objective-c - 如何在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);
提前致谢!
解决方案
someValue
在您的代码中是函数指针,而不是从相应函数返回的值。如果您需要打印从该函数返回的值,只需调用它:
printf("%f\n", someValue());
// ^^
不言而喻,您必须检查NULL
来自dlsym
.
推荐阅读
- heroku - heroku CLI 通过令牌进行身份验证
- javascript - 如何使用 javascript 将元素附加到空的 html 文件?
- mongodb - MongoDB - 如何在 $group 中使用 $in 时返回数组中的匹配项?
- sql - 使用参数创建新函数并返回表时出现 DB2 SQL 错误
- regex - 使用正则表达式在 VSCode 中搜索一组 XML 标记的多行内容
- reactjs - 当我们将状态放入 Redux 时,我们是否应该将类组件更改为功能组件?
- javascript - NextJS routeChangeComplete 不会在 _app.js 上触发
- flutter - 如何在 Flutter 中为 appbar 标题设置默认文本样式?
- java - DocumentBuilder.class 运算符在 System Classloader 中加载类
- java - 使用 Android Studio 获取每日使用情况统计信息