14-08-2023, 01:58 PM
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?
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?