代码:
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 MATLAB yalmip 可转移负荷的简单建模出错,如何解决?
- ¥15 数学的三元一次方程求解
- ¥20 iqoo11 如何下载安装工程模式
- ¥15 本题的答案是不是有问题
- ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
- ¥15 C++使用Gunplot
- ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
- ¥15 matlab数字图像处理频率域滤波
- ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
- ¥15 ELGamal和paillier计算效率谁快?