Useless preprocessor conditional directive
Description
This defect occurs when a preprocessor conditional directive always evaluates to the same logical value. For instance, you might be testing for the condition in a previous conditional directive. Consider this code:
long sensorFlag; #if cond1 sensorFlag = 0x0001; #elif cond2 sensorFlag = 0x00AA; #else #if cond1 //Always false sensorFlag = 0xFF00; #endif #endif
#else
block, the conditional directive #if cond1
is
executed only when cond1
is false. This directive is always
false
. Polyspace® flags conditional directive that always evaluates to the same logical
value.Risk
If a conditional directive is always true or always false, it might indicate an
inadvertent error. For instance, the conditional directive might be unexpectedly impacted by
a change elsewhere in your code. Alternatively, your conditional directive design might
contain unexpected errors. In the preceding code, the statement #if cond1
might be a typographical error. The developer intent might have been to use #if
cond3
.
Fix
To fix this defect, remove the flagged conditional directive. If the useless conditional is unexpected, review and refactor your code.
Examples
Result Information
Group: Data flow |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
USELESS_PREPROC_CONDITION |
Impact: Low |
Version History
Introduced in R2022a
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)