In a - b
, the operands are promoted to int
before the subtraction, so the result is -255, not 1.
That's why both the first and second examples fail; it's nothing to do with the other operand of ==
. The third converts -255 back to uint8_t
, reducing it modulo 256, so the result is 1 as expected.