gpt4 book ai didi

c - strtof 未定义;假设 extern 返回 int

转载 作者:行者123 更新时间:2023-11-30 14:59:07 24 4
gpt4 key购买 nike

可能这是一个非常愚蠢的问题,但我不明白......为了从 ASCII 表示转换为相关数字,我在 Visual Studio 2012 中使用 strtof()。根据 https://msdn.microsoft.com/en-us/library/dn320175.aspx (根据 Linux 手册页,它可以用 gcc 很好地编译)stdlib.h 需要包含在内。

现在我的问题是:我已经一个 #include <stdlib.h>在我的文件中,但仍然出现此编译错误!

知道可能缺少什么吗?

谢谢!

编辑:代码示例

#include <stddef.h>
#include <stdlib.h>

static char *get_xyz(char *c,float *x,float *y,float *z)
{
c++;

if ((*c=='X') || (*c == 'A') || (*c=='x') || (*c=='a'))
{
c++;
if (*c) *x=strtof(c,NULL);
}

if ((*c=='Y') || (*c=='B') || (*c=='y') || (*c=='b'))
{
c++;
if (*c) *y=strtof(c,NULL);
}

if (z)
{
if ((*c=='Z') || (*c=='C') || (*c=='z') || (*c=='c'))
{
c++;
if (*c) *z=strtof(c,NULL);
}
}

return c;
}

最佳答案

问题在于 Visual Studio 不符合 C 标准。 strtof 于 1999 年在 C 语言中引入,距 VS2012 发布仅 13 年。 Microsoft 尚未针对这些更改更新其编译器。

我认为他们现在终于在 VS2015 版本中引入了对这个(以前的)C 语言标准的部分支持。我认为他们根本不支持 2011 年以来的当前 C 标准。

最好的选择是使用符合标准的 C 编译器。

关于c - strtof 未定义;假设 extern 返回 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42993356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com