Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.5, shift left operator example
#5
The purpose of Rule 10.5 is to remove ambiguity and any dependency on the size of int when performing bitwise shift and bitwise complement operations.

There are clearly situations where addition of a cast might seem unnecessary. However it is unfortunately true that the great majority of C developers do not understand the mechanism of integral promotion and imposition of this rule is intended to provide some protection against ignorance.

With reference to the specific example, it does appear that the value is independent of the size of the implemented int type and that the explanatory text is therefore incorrect. However, the value of a similar expression with different types (uint_16 instead of uint_8 for example) or with different shift constants would depend on the int type. Therefore, in general the comment applies even if not to this particular example.

Tracker ID: 0000016
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)