Why am I getting :
(373)implicit signed to unsigned conversion
by doing:
fan_on_hh = hh + fan_hh_increment
All fan_on_hh
, hh
and fan_hh_increment
are unsigned char
.
This post suggests to do this:
fan_on_hh = (unsigned char) hh + fan_hh_increment
But I keep getting the same warning by doing that.
Is there a way to stop these warnings?
Integer types smaller than
int
(e.g.unsigned char
) are promoted toint
when an operation is performed on them. If all values of the original type can be represented as anint
, the value of the smaller type is converted to anint
.So in your example
hh
andfan_hh_increment
are promoted toint
before the addition.When you want to stop the warning, you had to cast the result to
unsigned char
: