MISRA C:2012 Rule 10.8 Clarification - 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:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 8.10 The essential type model (https://forum.misra.org.uk/forumdisplay.php?fid=165) +---- Thread: MISRA C:2012 Rule 10.8 Clarification (/showthread.php?tid=1655) |
MISRA C:2012 Rule 10.8 Clarification - uk000032 - 14-08-2023 MISRA C:2012 Rule 10.8 states "The value of a composite expression shall not be cast to a different essential type category or a wider essential type". One example of a violation given is: ( uint32_t ) ( u16a + u16b ) /* Non-compliant - cast to wider * essential type */ But what about: ( uint32_t ) u16a + ( uint32_t ) u16b /* Compliant? */ This kind of thing does get flagged by Polyspace 2022b as a violation of Rule 10.8, but am I correct in thinking that casting the variables before the compound operator is applied means that this not in fact a violation? RE: MISRA C:2012 Rule 10.8 Clarification - misra-c - 08-02-2024 The Compliant? statement is, indeed, compliant, as there is no composite statement - each object is promoted to uint32_t independently. |