【问题标题】:Odd Compiler Error in C++ (VC compiler)C++ 中的奇怪编译器错误(VC 编译器)
【发布时间】:2014-10-24 16:10:10
【问题描述】:

对于这段代码,

#include <math.h>
int main()
{
    float x = 1.5f;
    float y = 0.0f;
/*line6*/   y = pow(x, 6) * 235809835.41 - pow(x, 5) * 2110439254.2 + pow(x, 4) *7869448124.8 - pow(x, 3) * 15648965509 + pow(x, 2) * 17503313074 - (x)* 10440563329 + 2594694745‏; // error
/*line7*/   y = pow(x, 6) * 235809835.41 - pow(x, 5) * 2110439254.2 + pow(x, 4) *7869448124.8 - pow(x, 3) * 15648965509 + pow(x, 2) * 17503313074 - (x)* 10440563329 + 2594694745;
    return 0;
}

我收到以下错误日志 -

maincpp.cpp(6) : warning C4244 : '=' : conversion from 'double' to 'float', possible loss of data
maincpp.cpp(6) : error C2146 : syntax error : missing ';' before identifier '‏'
maincpp.cpp(6) : error C2065 : '‏' : undeclared identifier

第 6 行编译失败。最令我吃惊的是,第 7 行与第 6 行相同,但仍然可以编译。因此,如果我将第 6 行注释掉并保留第 7 行,则程序编译成功。

我使用的是 64 位 Windows 8,这个程序是在 Visual Studio 2013 中作为 Win 32 控制台应用程序编写的。

在生产代码中,我会用 f 终止所有浮点文字。但无论如何,我不希望没有它会出现编译器错误。

公式是在 Excel 中生成的。

【问题讨论】:

  • 我们能看到完整的代码吗? (从 1 到 7)?
  • @jd6,所有的行都在那里 - 1 到 7
  • 抱歉我的疏忽。
  • 您的源代码被损坏了,它在 5 和 ; 之间包含一个不可打印的 Unicode 字符在第 6 行,U+200F。它是从右到左标记格式字符。你看不到它,虽然“'‏' : undeclared identifier”错误消息是一个很好的提示,但是编译器看到它并抱怨。注意从网站复制/粘贴代码。

标签: c++ visual-c++ compiler-errors floating-point typechecking


【解决方案1】:

看起来你在第 6 行的分号前有一个流浪的right-to-left mark:

... 2594694745<U+200F>; 

【讨论】:

  • 复制到 Vim 中;果然,这就是原因。见鬼去吧。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-23
  • 1970-01-01
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
相关资源
最近更新 更多