MISRA Discussion Forums

Full Version: Left Shifts and Castings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is the following acceptable under 10.5?
unsigned char u = 1u;
(unsigned char) u
Yes that is correct. The result must be typecasted in order to conform with rule 10.5.

The typecast to unsigned char in the first example will not have any effect at all. The typecast operator has higher priority than
uint8_t u =1;
uint8_t v;
uint8_t w;

v = u