- 论坛徽章:
- 0
|
各位大侠,小弟在写一个程序时有一个疑问:GCC为什么不会对double赋值给float型变量产生告警?VC上则会告警,我的系统是Ubuntu 12.0,
程序如下:
ncludei<stdio.h>
int main()
{
int lowest = 0;
int uppest = 300;
int step = 20;
int fahr = lowest;
float celsius;
while(fahr <= uppest)
{
celsius = 5.0 / 9 * (fahr - 32);
printf("fahr = %d\tcelsius=%f\n", fahr, celsius);
fahr += step;
}
printf("sizeof(float)= %d,\tsizeof(double)= %d, sizeof(long double)= %d\n", sizeof(float), sizeof(double), sizeof(long double));
return 0;
}
编译时没有产生告警,我预期是在 celsius = 5.0 / 9 * (fahr - 32);产生告警的。另外 printf("sizeof(float)= %d,\tsizeof(double)= %d, sizeof(long double)= %d\n", sizeof(float), sizeof(double), sizeof(long double));输出的结果如下:sizeof(float)= 4, sizeof(double)= 8, sizeof(long double)= 12
请大神指点,多谢~
|
|