20-06-2006, 12:48 PM
In section 6.10.4, we indicate that unsigned values between 0 and 255 are treated as having an underlying type of unsigned 8 bits.
Therefore 10U is treated as having an underlying type of unsigned 8 bit .
Your code example
should not generate any warnings.
Your code example
should generate a warning because a U16 expression is being narrowed into a U8 result - 10.1a.
should generate a warning because a U32 expression is being narrowed into a U8 result - 10.1a.
Writing just
is compliant. The result of a U8 expression is stored in a U8 variable.
This is an area were MISRA-C:2004 is significantly different than MISRA-C:1998.
Therefore 10U is treated as having an underlying type of unsigned 8 bit .
Your code example
Code:
U16 u16value;
U8 u8value;
u16value = (U16) u8value / 10U;
should not generate any warnings.
Your code example
Code:
U16 u16value;
U8 u8value;
u8value = (U16) u8value / (U16)10U;
should generate a warning because a U16 expression is being narrowed into a U8 result - 10.1a.
Code:
U8 u8a;
U8 u8b;
U8 u8c;
U8a = (U32) u8b / (U32) u8c;
should generate a warning because a U32 expression is being narrowed into a U8 result - 10.1a.
Writing just
Code:
U8a = u8b / u8c;
is compliant. The result of a U8 expression is stored in a U8 variable.
This is an area were MISRA-C:2004 is significantly different than MISRA-C:1998.
Posted by and on behalf of the MISRA C Working Group