Results of comparing integers in C -
if x
, y
both int
, x-y < 0
return same result x < y
?
no. if x-y
causes overflow or underflow, behavior undefined (because int signed type).
for example int_min - 1 < 0
undefined behavior, whereas int_min < 1
defined (and true).
when there's no overflow, 2 expressions, x-y < 0
, x < y
same.
because compiled code may whatever likes when there's undefined behavior, c compiler allowed rewrite x-y < 0
x < y
if wishes. isn't true if x
, y
unsigned types, overflow well-defined, , x-y < 0
, x < y
not equivalent.
Comments
Post a Comment