对于无符号整形溢出的理解
例如,在 int 类型为16 位、long 类型为32 位的机器上:
#define START 0x8000
#define END 0xFFFF
#define LEN 0x8000
#if ( (START + LEN ) > END )
#error Buffer Overrun /* OK because START and LEN are unsigned long */ 此处1
#endif
#if ( ( ( END – START ) – LEN ) < 0 )
#error Buffer Overrun
/* Not OK: subtraction result wraps around to 0xFFFFFFFF */
#endif
/* contrast the above START + LEN with the following */
if ( ( START + LEN ) > END )
{
error ( “Buffer overrun “ );
/* Not OK: START + LEN wraps around to 0x0000 due to //此处2
unsigned int arithmetic */
}
这2处为什么结构是不一样,用预定义可以扩展到long, 用if 的只能到 int