Signed/unsigned comparisons

When comparing signed with unsigned, the compiler converts the signed value to unsigned. For equality, this doesn’t matter, -1 == (unsigned) -1. For other comparisons it matters, e.g. the following is true: -1 > 2U. EDIT: References: 5/9: (Expressions) Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result … Read more

Comparison operation on unsigned and signed integers

Binary operations between different integral types are performed within a “common” type defined by so called usual arithmetic conversions (see the language specification, 6.3.1.8). In your case the “common” type is unsigned int. This means that int operand (your b) will get converted to unsigned int before the comparison, as well as for the purpose … Read more