A value does not determine its type
The expressions `-1` and `-1U` begin with different integer literals. The decimal literal `1` has a signed type; the suffix `U` forces `1U` to have an unsigned type. The minus sign is an operator applied to the literal, not part of it. Consequently, `-1U` is not a signed negative value. section 5.3
An integer type represents whole numbers. C divides integer types into signed and unsigned classes. Each type has a precision that limits its range, but the C standard constrains rather than fixes the precision of the base types. Signed and unsigned types generally come in corresponding pairs by integer rank; `char` and `bool` are exceptions. section 5.2 section 5.7.5
Rules to keep in mind:
- Before arithmetic, narrow integer types are promoted. On realistic platforms, this produces a `signed int` with the same value, even when the narrow type is unsigned. section 5.2
- A decimal integer literal takes the first signed type that fits. A binary, octal or hexadecimal literal may instead take an unsigned type. Use decimal notation for negative values. section 5.3
- A positive signed value has the same representation as its corresponding unsigned value. C23 requires two’s-complement sign representation for signed integers. section 5.7.5
When spelling changes the type
Suppose `signed int` has a maximum of 32,767. The decimal literal `32768` does not fit, so it has type `signed long`; `-32768` is the negation of that long value. Under the same assumption, `0x8000` can have an unsigned type, making `-0x8000` unsigned too. Never infer a negative value from a hexadecimal bit pattern alone. section 5.3
Table 5.3 Examples for literals and their types, under the supposition that signed and unsigned have the commonly used representation with 32 bits
| Literal 𝑥 | Value | Type | Value of -𝑥 |
| 2'147'483'647 | +2,147,483,647 | signed | -2,147,483,647 |
| 2'147'483'648 | +2,147,483,648 | signed long | -2,147,483,648 |
| 4'294'967'295 | +4,294,967,295 | signed long | -4,294,967,295 |
0x7FFF'FFFF |
+2,147,483,647 | signed | -2,147,483,647 |
0x8000'0000 |
+2,147,483,648 | unsigned | +2,147,483,648 |
0xFFFF'FFFF |
+4,294,967,295 | unsigned | +1 |
| 1 | +1 | signed | -1 |
| 1U | +1 | unsigned | +4,294,967,295 |
Compare literal values, inferred types and the results of negation under the table’s stated 32-bit assumptions. section 5.3
Integer types also serve specific roles: `size_t` represents sizes and cardinalities, while `ptrdiff_t` represents size differences. In structures, integer bit-fields can specify member widths; choosing a width still requires checking the values that member must hold. section 5.2 section 6.3.4














