Originally posted by oiaohm
View Post
- The rank of any unsigned integer type shall equal the rank of the corresponding signed integer type, if any.
- If the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type is converted to the type of the operand with unsigned integer type.
- That modulo rule for converting to unsigned: «Otherwise, 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.»
Code:
signed int si = -1; unsigned int ui = ~0; if(si == ui) // does what it looks like if(si != ui) // does what it looks like if(si < ui) // doesn't do what it looks like
Of course, that inequality comparison is defined the wrong way, and had the signed type had highest rank, this wouldn't even be defined. So yes, -Wsign-compare is of course legitimate in a lot of cases.
Comment