Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
conversions with constant
#2
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.


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)