Consider the reason why you receive a warning, namely that the integer constant 8 is of type int . That everything in C needs to be upgraded to (signed) int is a well-known flaw in language design.
Suppose you had byte += 256; or byte += -1; or byte += function_that_returns_int(); . All of them are potentially serious errors, therefore the warning certainly makes sense to include.
In fact, there is no other work than to cast the result of the operation to the supposed type uint8_t . This is not necessarily bad, because it creates self-documenting code saying "yes, I really looked at the types that are used in this calculation, so there should be no overflows."
source share