MISRA C++:2008 Rule 5-0-21
Bitwise operators shall only be applied to operands of unsigned underlying type
Description
Rule Definition
Bitwise operators shall only be applied to operands of unsigned underlying type.
Rationale
Bitwise operations are not meaningful when they are applied to signed operands. Applying bitwise operations to signed operands might result in an unexpected and implementation dependent result. For instance, if you right shift a negative number, the result varies depending on your environment. Avoid using bitwise operations on signed operands.
Polyspace Implementation
Polyspace® raises a violation of this rule when you apply a bitwise operation on a signed operand or expression.
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