Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 12.7 and underlying type
#1
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)
#2
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.
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 1 Guest(s)