Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Constant Size and Rule 12.2
#2
In replying to this question it is necessary to understand the distinction between the standard types as described in the C standard and essential types as described in the MISRA C:2012 guidelines. The rationale and description of the MISRA essential types can be found in section 8.10 and Appendices C and D of the MISRA C:2012 guidelines.

You are correct in saying that the smallest C standard type for an integer constant with no suffix is "signed int". However, the essential type is the type with lowest rank that can represent the value. This is defined in Appendix D.3. In the above example this means that "1" has an essential type of "essentially signed char". And hence 15 would exceed the maximum value of 7 that is permitted for shifting an "essentially signed char".

The MISRA essential types model produces a internally consistent view of C types, but a side-effect of keeping the model simple has been that a few integer constant expressions may violate some MISRA guidelines. Your example is one of those occasions and is similar to that given in the example section of rule 12.2 where "1u
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)