Unused parameter
Function prototype has parameters not read or written in function body
Description
This defect occurs when a function parameter is neither read nor written in the function body. The checker does not flag unused parameters in functions with empty bodies.
Risk
Unused parameters can indicate that the code is possibly incomplete. The parameter is possibly intended for an operation that you forgot to code.
If the copied objects are large, redundant copies can slow down performance.
Fix
Determine if you intend to use the parameters. Otherwise, remove parameters that you do not use in the function body.
You can intentionally have unused parameters. For instance, you have parameters that you intend to use later when you add enhancements to the function. Add a code comment indicating your intention for later use. The code comment helps you or a code reviewer understand why your function has unused parameters.
Alternatively, add a statement such as (void)var;
in
the function body. var
is the unused parameter.
You can define a macro that expands to this statement and add the
macro to the function body.
Examples
Result Information
Group: Good practice |
Language: C | C++ |
Default: Off |
Command-Line Syntax: UNUSED_PARAMETER |
Impact: Low |
Version History
Introduced in R2015b
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)