MISRA C:2012 Rule 2.8
Description
Rule Definition
A project should not contain unused object definitions.1
Rationale
An object is unused if the program compiles after removing the definitions and declarations of the object. Such unused objects can be confusing because it is not clear whether such objects are redundant or left unused by mistake.
Polyspace Implementation
Polyspace® reports violations on unused variables with internal linkage, such as:
Unused local variables
Unused global variables declared
static
Unused global variables declared outside a header file with a
const
qualifier but not anextern
qualifier
The rule violation is reported on the variable declaration. Polyspace does not report violations on unused function parameters.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Unused code |
Category: Advisory |
AGC Category: Advisory |
Version History
Introduced in R2024b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.