25-01-2023, 04:37 PM
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.
Thanks for your help!
Rafe
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