05-01-2006, 10:33 AM
ANSWER: MISRA C Steering team 5/1/06
See page 40 in MISRA-C:2004
u8a = 5U;
The underlying type of 5U ( a constant), is the smallest unsigned integral type into which it fits. This is U8 (unsigned 8-bit) and therefore this value CAN be assigned to u8a.
u8a=u16b;
The underlying type of u16b is U16 (unsigned 16-bit). The assignment involves an implicit conversion to a narrower type and violates rule 10.1.
u8a = 5UL;
The underlying type of 5UL ( a constant), is unsigned long U32. The assignment involves an implicit conversion to a narrower type and violates rule 10.1.
See page 40 in MISRA-C:2004
u8a = 5U;
The underlying type of 5U ( a constant), is the smallest unsigned integral type into which it fits. This is U8 (unsigned 8-bit) and therefore this value CAN be assigned to u8a.
u8a=u16b;
The underlying type of u16b is U16 (unsigned 16-bit). The assignment involves an implicit conversion to a narrower type and violates rule 10.1.
u8a = 5UL;
The underlying type of 5UL ( a constant), is unsigned long U32. The assignment involves an implicit conversion to a narrower type and violates rule 10.1.