The type of an integer is dependent on a complex combination of factors including:
- The magnitude of the constant;
- The implemented sizes of the integer types;
- The presence of any suffixes;
- The number base in which the value is expressed (i.e. decimal, octal or hexadecimal).
For example, the value 0x8000 is of type unsigned int
in a 16-bit environment, but of type (signed
) int
in a
32-bit environment.
Note:
- Any value with a "U" suffix is of unsigned type;
- An unsuffixed decimal value less than 2^31 is of signed type.
But:
- An unsuffixed hexadecimal value greater than or equal to 2^15 may be of signed or unsigned type;
- For C90, an unsuffixed decimal value greater than or equal to 2^31 may be of signed or unsigned type.
In C++, if an overload set includes candidates for an unsigned int
and an int
, then the overload that would be matched by
0x8000 is therefore dependent on the implemented integer size. Adding a "U" suffix to the value specifies that it is unsigned.