Signed integers shall not be combined with unsigned integers in comparisons or expressions. Insupport of this, decimal constants meant to be
unsigned should be declared with a u at the end.
Example:
uint8_t a = 6u;
int8_t b = -9;
if (a + b < 4)
{
// This correct path should be executed
// if -9 + 6 were -3 < 4, as anticipated.
}
else
{
// This incorrect path is actually executed,
// as -9 + 6 becomes (0xFF 9) + 6 = 252.
}
unsigned should be declared with a u at the end.
Example:
uint8_t a = 6u;
int8_t b = -9;
if (a + b < 4)
{
// This correct path should be executed
// if -9 + 6 were -3 < 4, as anticipated.
}
else
{
// This incorrect path is actually executed,
// as -9 + 6 becomes (0xFF 9) + 6 = 252.
}