Since "sum" is an unsigned type that the "-1" gets converted to an unsigned type as well (see below). This results in a very large number (how large depends on the machine) being compared to.
So try this conversion on paper:
-1 to a binary number (try just using 2 bytes), then that binary number to an unsigned number. The exact number is machine dependent (on your int size), but basically you are comparing sum to a very large number, thus the results you are seeing.
Committee Draft — April 12, 2011
6.3.1.8 Usual arithmetic conversions
First, if the corresponding real type of either operand is long double, the other operand is converted, without change of type domain, to a type whose corresponding real type is long double.
Otherwise, if the corresponding real type of either operand is double, the other operand is converted, without change of type domain, to a type whose corresponding real type is double.
Otherwise, if the corresponding real type of either operand is float, the other operand is converted, without change of type domain, to a type whose corresponding real type is float. 62)
Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands: If both operands have the same type, then no further conversion is needed.
Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank.
The relevant part:
Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.
Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type.
Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type.
CHAR_BIT * sizeof(unsigned).if( sum > -1 ) …(-1has typeintandsumis anunsigned int). If it doesn't, find how to enable this warning before any further effort.