MISRA Discussion Forums
Left Shifts and Castings - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.10 Arithmetic Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=37)
+---- Thread: Left Shifts and Castings (/showthread.php?tid=505)



Left Shifts and Castings - gs - 05-05-2008

Is the following acceptable under 10.5?
[code]
unsigned char u = 1u;
(unsigned char) u


Re: Left Shifts and Castings - Lundin - 06-05-2008

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


Re: Left Shifts and Castings - misra-c - 24-09-2008

[code]
uint8_t u =1;
uint8_t v;
uint8_t w;

v = u