在 Keil MDK-ARM C++11 *默认 NAN 值* 成员和函数的参数生成奇怪的错误
In Keil MDK-ARM C++11 *default NAN value* for member and function's parameter generates strange errors
你有没有遇到过另一个 Keil 的“feature”当下一个代码
#include <cmath>
struct AB {
float f=NAN;
float foo(float a=NAN);
};
生成下一个构建输出:
compiling main.cpp...
..\..\src\main.cpp(24): error: #65: expected a ";"
float foo(float a=
AN);
..\..\src\main.cpp(24): error: #109: expression preceding parentheses of apparent call must have (pointer-to-) function type
float foo(float a=NAN);
..\..\src\main.cpp(24): error: #18: expected a ")"
float foo(float a=NAN);
..\..\src\main.cpp(24): error: #18: expected a ")"
float foo(float a=NAN);
..\..\src\main.cpp(23): error: #65: expected a ";"
float f=NAN;
..\..\src\main.cpp: 0 warnings, 5 errors`
对我来说,它看起来像是错误。我从未在 GCC 和其他编译器中遇到过同样的麻烦。
5 个错误 2 行。极好的。什么鬼? MDK-ARM 无法解析 NAN
.
这可以在下一行修复:
#define __ESCAPE__(__x) (__x)
最好只为这个“cool”编译器制作它:
#ifdef __CC_ARM
#define __ESCAPE__(__x) (__x)
#endif
另一个解决方案(不确定,但可能是编译器的扩展):
float f = 0f_7FC00000;
你有没有遇到过另一个 Keil 的“feature”当下一个代码
#include <cmath>
struct AB {
float f=NAN;
float foo(float a=NAN);
};
生成下一个构建输出:
compiling main.cpp... ..\..\src\main.cpp(24): error: #65: expected a ";" float foo(float a= AN); ..\..\src\main.cpp(24): error: #109: expression preceding parentheses of apparent call must have (pointer-to-) function type float foo(float a=NAN); ..\..\src\main.cpp(24): error: #18: expected a ")" float foo(float a=NAN); ..\..\src\main.cpp(24): error: #18: expected a ")" float foo(float a=NAN); ..\..\src\main.cpp(23): error: #65: expected a ";" float f=NAN; ..\..\src\main.cpp: 0 warnings, 5 errors`
对我来说,它看起来像是错误。我从未在 GCC 和其他编译器中遇到过同样的麻烦。
5 个错误 2 行。极好的。什么鬼? MDK-ARM 无法解析 NAN
.
这可以在下一行修复:
#define __ESCAPE__(__x) (__x)
最好只为这个“cool”编译器制作它:
#ifdef __CC_ARM
#define __ESCAPE__(__x) (__x)
#endif
另一个解决方案(不确定,但可能是编译器的扩展):
float f = 0f_7FC00000;