【发布时间】: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