MISRA Discussion Forums

Full Version: M5-0-20 clarification
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

Rule 5-0-20 states that "Non-constant operands to a binary bitwise operator shall have the same underlying type." seems to make sense but my colleagues and I are bit unsure why the non-constant qualifier? 

Consider the following example. It's not clear to us why the first should be allowed if the second is not.
Code:
int foo(int i) {
  const unsigned char mask = ~(0x10);
  return i ^ mask; // compliant: mask is const
}

int foo(int i) {
  unsigned char mask = ~(0x10);
  return i ^ mask; // non-compliant: mask is not const and a different type than i
}


Thanks for your help!
Rafe
The intent of the rule was to apply to expressions that could be evaluated at compile-time.

Hence both your examples are non-compliant.

This will be addressed in the new version - due imminently.