MISRA Discussion Forums

Full Version: MISRA C:2012 Rule 10.8 Clarification
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
The Compliant? statement is, indeed, compliant, as there is no composite statement - each object is promoted to uint32_t independently.