【发布时间】:2015-06-25 16:05:24
【问题描述】:
我在 windows 上摆弄 GCC 4.9.2,发现它不会警告从 double 到 int 的转换,而 Visual Studio 编译器会:
代码:
int main()
{
int celsius, fahrenheit, kelvin;
celsius = 21;
fahrenheit = celsius * 9 / 5 + 32;
kelvin = celsius + 273.15; //here it should warn!
printf("%d C = %d F = %d K",
celsius, fahrenheit, kelvin);
return 0;
}
我编译使用:
gcc hello.c -Wall -Wextra -pedantic -std=c99
我用 Visual Studio 编译器编译了相同的代码:
C:\temp>cl hello.c /nologo /W4 /FeC2f.exe
hello.c
hello.c(14): warning C4244: '=': conversion from 'double' to 'int', possible loss of data
我做错了什么?
【问题讨论】: