This expression will have type int
, which is signed.
Because both operands have a type smaller than int
, both will be promoted to type int
, and the result will have type int
.
Integer promotions are defined in section 6.3.1.1p2 of the C standard:
The following may be used in an expression wherever an int
or
unsigned int
may be used:
- An object or expression with an integer type (other than int or unsigned int) whose integer conversion rank is less than or equal to
the rank of
int
and unsigned int
.
- A bit-field of type
_Bool
, int
, signed int
, or unsigned int
.
If an int
can represent all values of the original type (as restricted
by the width, for a bit-field), the value is converted to an int
;
otherwise, it is converted to an unsigned int
. These are called the
integer promotions. All other types are unchanged by the integer promotions.
So this means the expression ((a - b) < 0)
could potentially evaluate as true.
Had the variables been defined like this:
unsigned int a;
unsigned int b;
Then there would be no promotion and a - b
would have unsigned type, meaning ((a - b) < 0)
would always be false.