Unused variable
Description
This defect occurs when a nonstatic local, static local, or static global variable is
declared or defined but not read in any source files within the scope of the Polyspace® analysis. Polyspace does not report this defect for variables that are members of a class,
struct
, or union
.
Risk
An unused variable can indicate possible logic errors or architectural errors in your code. If an unused variable is expensive to construct or destroy, then it can make the code unnecessarily expensive.
Fix
To fix this defect, review your code and determine why variables are unused. Remove unnecessary variables and revise your code so that remaining variables are used.
Examples
Result Information
Group: Good Practice |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
UNUSED_VARIABLE
|
Impact: Low |
Version History
Introduced in R2024aSee Also
Find defects
(-checkers)
| Expensive pass by
value
| Expensive return by
value
| Expensive copy in a range-based
for loop iteration
| Expensive local variable
copy
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)