Code deactivated by constant false condition
Code segment deactivated by #if 0
directive
or if(0)
condition
Description
This defect occurs
when a block of code is deactivated using a #if 0
directive
or if(0)
condition.
Risk
A #if 0
directive or if(0)
condition is used
to temporarily deactivate segments of code. If your production code contains these
directives, it means that the deactivation has not been lifted before shipping the
code.
Fix
If the segment of code is present for debugging purposes only, remove the segment
from production code. If the deactivation occurred by accident, remove the
#if 0
and #endif
statements.
Often, a segment of code is deactivated for specific conditions, for instance, a
specific operating system. Use macros with the #if
directive to
indicate these conditions instead of deactivating the code completely with a
#if 0
directive. For instance, GCC provides macros to detect
the Windows® operating
system:
#ifdef _WIN32 //Code deactivated for all operating systems //Other than 32-bit Windows #endif
If you do not want to fix the issue, add comments to your result or code to avoid another review. See:
Address Results in Polyspace User Interface Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Annotate Code and Hide Known or Acceptable Results if you review results in an IDE.
Examples
Result Information
Group: Data flow |
Language: C | C++ |
Default: off |
Command-Line Syntax: DEACTIVATED_CODE |
Impact: Low |
Version History
Introduced in R2013b
See Also
Find defects (-checkers)
| Unreachable code
| Useless if
| Dead code
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)