What can I do to avoid MISRA giving this error for the code below? I tried casting with (unit16_t). But then it didn\'t allow an explicit conversion.
Illegal implici
The implicit conversion is performed before the multiplication, for the multiplication. Maybe an explicit conversion right before the multiplication shuts up your tool
uint16_t basic_units = (unsigned)rate * (unsigned)percentage;
The resulting unsigned
value, should be implicitly converted to uint16_t
with no warnings. If your tool chooses to be a PITA about this too, try another explicit conversion:
uint16_t basic_units = (uint16_t)((unsigned)rate * (unsigned)percentage);