Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Constant Size and Rule 12.2
#1
Hi Folks,

I'm trying to come to an understanding of an issue associated with MISRA 2012 Rule 12.2 and the interpretation of constant size. Here is the situation I'm dealing with.

=====================================================================
int32_t result;

result = (1
<t></t>
#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
#3
Thanks for your response...

-Michael
<t></t>
#4
I have recently had a dialogue with the support at Programming Research, since we use their QA-C static analysis tool with the MISRA-C:2012 add-on. My example:

extern unsigned int getShift(void);
const unsigned int shift = getShift();
const unsigned int multiplier = 1u
<t></t>
#5
Thank you for your feedback. The essential type system is designed to be stricter than the standard C type system. The messages are consistent with the MISRA-C guidelines.

It is inappropriate for us to comment on the output of individual tools.
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 3 Guest(s)