i*****s 发帖数: 438 | 1 I was reading CSAPP2 and couldn't get this example
(regarding singed/unsigned integer):
#define DELTA sizeof(int)
int i;
for (i = CNT; i-DELTA >= 0; i-= DELTA)
. . .
the for() loop will not stop?
Thanks. | t****t 发帖数: 6806 | 2 sizeof() has unsigned type. as a result of [usual arithmetic conversions] (
standard 5, clause 9), in "i-DELTA", int is converted to unsigned; then "i-
DELTA>=0", 0 is converted to unsigned. thus the condition is always true,
since by definition, any unsigned number is >=0.
【在 i*****s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I was reading CSAPP2 and couldn't get this example : (regarding singed/unsigned integer): : #define DELTA sizeof(int) : int i; : for (i = CNT; i-DELTA >= 0; i-= DELTA) : . . . : the for() loop will not stop? : Thanks.
| i*****s 发帖数: 438 | 3
谢谢!以后还请多赐教!
【在 t****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : sizeof() has unsigned type. as a result of [usual arithmetic conversions] ( : standard 5, clause 9), in "i-DELTA", int is converted to unsigned; then "i- : DELTA>=0", 0 is converted to unsigned. thus the condition is always true, : since by definition, any unsigned number is >=0.
|
|