30-03-2009, 10:00 AM
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
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