First of all, in C, %
is not the modulo operator. It is the remainder operator.
Otherwise, you're right that integer promotion happens. uint8_t
is implicitly converted to an int
when it appears as the argument of an arithmetic operator.
So when x
reaches 0, then x - 1
will become -1. Then, -1 % 10
is -1 (and not 9), and -1 assigned to uint8_t
yields 255 (since unsigned integer overflow is defined in terms of modulo arithmetic).