【问题标题】:strtof undefined; assuming extern returning intstrtof 未定义;假设 extern 返回 int
【发布时间】:2017-08-17 00:42:03
【问题描述】:

这可能是一个非常愚蠢的问题,但我不明白...为了从 ASCII 表示转换为相关数字,我在 Visual Studio 2012 中使用 strtof()。根据https://msdn.microsoft.com/en-us/library/dn320175.aspx(和accordng to使用 gcc 可以正常编译的 Linux 手册页)需要包含 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;
}

【问题讨论】:

  • 你能展示一个 MCVE 吗? stackoverflow.com/help/mcve
  • 发布错误和代码。
  • 对应于 Visual Studio 2013 或更高版本。使用strtod 而不是strtof
  • @BLUEPIXY:谢谢,这就是解决方案!

标签: c visual-studio visual-studio-2012


【解决方案1】:

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

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

最好的办法是改用符合标准的 C 编译器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    相关资源
    最近更新 更多