MISRA Discussion Forums

Full Version: Rule 12.7 and underlying type
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Question on 12.7: Bitwise operators shall not be applied to operands whose underlying type is signed

[code]int32_T var1[32];
uint16_T var2 = 5U;
int32_T var3 = var1[(var2 - 1)
MISRA-C meeting 22-8-2006

The array index sub-expression
Code:
var2 - 1
contains both unsigned and signed values (respectively) and is prohibited under rule 10.1.

The underlying type of a mixed signed / unsigned expression is undefined.

In your second example, the array index sub-expression
Code:
var2 - 1U
is unsigned, and therefore the shift can be applied.