I have read in many places that unsigned integer overflow is well-defined in C unlike the signed counterpart.
Is underflow the same?
For example:
unsigned int x = -1; // Does x == UINT_MAX?
Thanks.
I can't recall where, but i read somewhere that arithmetic on unsigned integral types is modular, so if that were the case then -1 == UINT_MAX mod (UINT_MAX+1).
§6.3.1.3 Signed and unsigned integers, paragraph 2:
if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.
So yes, x == UINT_MAX
.