Skip to content
UPEEC

Integer Promotions

Types smaller than `int` (char, short, bit-fields) are converted to `int` before arithmetic.

Intermediate
Comments 0
uint8_t a = 200, b = 100;
uint8_t c = a + b;   /* computed as int 300, then truncated to 44 */

This explains many surprising results with uint8_t and bitwise NOT: ~(uint8_t)0 is -1 as an int.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.