有如下代码:
#include <stdio.h>
int my_func(void)
{
/* float f = 0.0; */
return(0.0 ? 1 : 0);
}
int main(void)
{
printf("%s\n", ( my_func() ? "ONE" : "NIL") );
return 0;
}
在vc6.0和vs2010中运行,你能说出它的输出结果吗?
答案:ONE
以上代码在gcc中确是不同的结果。。。
或许是微软编译器的一个bug吧,求解释!
参考资料:
[1].http://stackoverflow.com/questions/18008126/floating-point-constant-comparison-0-0-1-0