Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
M5-0-20 clarification
#1
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
Reply


Messages In This Thread
M5-0-20 clarification - by rt1980 - 25-01-2023, 04:37 PM
RE: M5-0-20 clarification - by misra cpp - 10-11-2023, 03:03 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)