我正在探索使用strfromd、strfromf函数作为snprintf的替代方案,分别在我的 C 代码中将双精度、整数转换为字符串值。(我使用 Oracle 虚拟机 Ubuntu 20.04 版本进行构建。)
\n我已经包括了
\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nRun Code Online (Sandbox Code Playgroud)\n在我的代码中,但在编译过程中我收到以下警告:
\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nRun Code Online (Sandbox Code Playgroud)\n我可以通过声明以下内容在我的电脑中删除此警告:
\nint strfromd(char *restrict str, size_t n,const char *restrict format, double fp);\nint strfromf(char *restrict str, size_t n,const char *restrict format, float fp);\nRun Code Online (Sandbox Code Playgroud)\n在我的代码顶部(不确定这是否是正确的方法),并且通过我的虚拟机中的这一特定更改解决了警告,但是当在不同的环境中尝试时,我收到错误 - 对“ strfromd”的未定义引用错误并且我的构建崩溃了。
\n有人在使用任何strfromd//函数时遇到类似的问题吗strfromf?strfroml可以采取什么措施来消除代码执行的这些问题?
注意:\n我已经尝试过以下练习:
\n#define __STDC_WANT_IEC_60559_BFP_EXT__\n#include <stdlib.h>\nRun Code Online (Sandbox Code Playgroud)\n该警告在我的虚拟机中已得到解决,但在其他环境中仍然给出了对“strfromd”错误的未定义引用。
\n
strfromd()自版本 2.25 起, 、、strfromf()和strfroml()函数在 glibc 中可用。
所以你的系统需要有glibc2.25以后的版本。
此外,您还应该#define __STDC_WANT_IEC_60559_BFP_EXT__:
glibc 的功能测试宏要求(请参阅 feature_test_macros(7)):
Run Code Online (Sandbox Code Playgroud)strfromd(), strfromf(), strfroml(): __STDC_WANT_IEC_60559_BFP_EXT__
| 归档时间: |
|
| 查看次数: |
160 次 |
| 最近记录: |