Bitwise and arithmetic operations on the same data
Statement with mixed bitwise and arithmetic operations
Description
This defect occurs when bitwise and arithmetic operations are performed in the same expression.
Risk
Mixed bitwise and arithmetic operations
do compile. However, the size
of integer types affects the result of these mixed
operations. For instance, the arithmetic equivalent
of a left shift (<<
) by a
certain number of bits depends on the number of bits
in the variable being shifted and therefore on the
internal representation of its data type. With a mix
of bitwise and arithmetic operations, the same
expression can produce different results on
different targets.
Mixed operations also reduce readability and maintainability.
Fix
Separate bitwise and arithmetic operations, or use only one type of operation per statement.
Examples
Result Information
Group: Good Practice |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
BITWISE_ARITH_MIX |
Impact: Low |
Version History
Introduced in R2016b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)