Main Content
MISRA C++:2008 Rule 5-0-20
Non-constant operands to a binary bitwise operator shall have the same underlying type
Description
Rule Definition
Non-constant operands to a binary bitwise operator shall have the same underlying type.
Rationale
In a binary bitwise operation, if you use operands that have different underlying types, then it is not clear which type you considered when designing the operation. For instance, in this code:
uint8_t mask = ~(0x10); uint16_t value; value ^= mask; // Non-compliant
mask
or a 16-bit
mask
. To avoid such confusion, use the same underlying type for
nonconstant operands of binary bitwise operators.Polyspace Implementation
If the nonconstant operands of a binary bitwise operator have different underlying types, Polyspace® raises a violation of this rule.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required |
Version History
Introduced in R2013b