代码:
unsigned long a = 2560*60*60*233;
unsigned long b = 0x7FFFFFFF;
unsigned long c = 0xF0000000;
//unsigned long d = 234*2560*3600; //seems beyond 0x7FFFFFFF
unsigned long temp = 1000000;
//unsigned long e = 2560*3600*360 - temp;
unsigned long f = 2560*3600*180 - temp + 2560*3600*180;
//unsigned long g = 2560*3600*360 - temp;
//unsigned long f = 2560*3600*180 - 1000000 + 2560*3600*180;
以上被注释部分是会产生编译警告的,未注释部分不会出编译警告。 I Just want to know why?
VS2005 编译器对warning C4307: integral constant overflow提示原则
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 普通网友 2014-05-29 03:09关注
Int the expression of unsigned long d = 234*2560*3600 ,We know that the viriable of d can only represent the maximum value of 4294967295 .But the vc++ compiler consider numbers 234, 2560 and 3600 as the type of int defaultly.The int is signed , so the value changes from -2147483648 to 2147483647, but the value of 234*2560*3600 is 2156544000, which beyong the maximum value of int , so, you will get the warning above.The resolution is to add the postfix UL to 234 to make the complier regard 234UL as the type of unsigned long , then, you well find all things go as you wish.
解决 无用评论 打赏 举报
悬赏问题
- ¥15 三菱伺服电机按启动按钮有使能但不动作
- ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
- ¥15 js,页面2返回页面1时定位进入的设备
- ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
- ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
- ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
- ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号