人们可以做什么来了解他们的系统如何响应溢出情况?描述一种测试系统如何响应下溢情况的方法。
我确实了解什么是溢出和下溢,我在维基百科上查找了这一点,但我不明白如何在系统之间进行测试。
With unsigned
对于整数,C 要求下溢和上溢以某种方式表现。例如,请考虑以下情况:
unsigned int uintUnderflow = 0;
unsigned int uintOverflow = UINT_MAX;
printf("%u\n", --uintUnderflow); // Guaranteed to be UINT_MAX
printf("%u\n", ++uintOverflow); // Guaranteed to be 0
现在与signed
整数,实现可以根据需要定义下溢和溢出。这就是未定义行为的本质。如果您找不到有关其行为方式的文档,则必须自己进行实验:
int intUnderflow = INT_MIN;
int intOverflow = INT_MAX;
printf("%d\n", --intUnderflow); // Implementation defined
printf("%d\n", ++intOverflow); // Implementation defined
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)