代码:
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.
解决 无用评论 打赏 举报
悬赏问题
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?