![]() |
![]() |
1501 | ![]() |
||||
![]() | |||||||
| CMA declaration checks | |||||||
The object declared here is not referenced at any point within the project. During maintenance it is possible that a function or an object used in the original design, may be replaced or become redundant. If possible, the declaration should be removed in order to reduce the potential for confusion. Example:
// TU1.cpp
int globalObj = 0;
int main()
{
++globalObj;
}
// TU2.cpp
void bar()
{
}
In order to reduce the number of global variables, it is decided to
change this global variable into a local static.
Example:
// TU1.cpp
int globalObj = 0;
int & getGlobalObj()
{
static int obj = 0;
return obj;
}
int main()
{
++getGlobalObj();
}
// TU2.cpp
void bar ()
{
}
However, incorrectly, the declaration of globalObj has not been
removed. At a later stage, a bug fix is required and the developer
incorrectly changes TU2 so it now uses globalObj.
Example:
// TU1.cpp
int globalObj = 0;
int & getGlobalObj()
{
static int obj = 0;
return obj;
}
int main()
{
++getGlobalObj();
}
// TU2.cpp
extern int globalObj;
void bar ()
{
++globalObj; // ERROR: This variable was no longer used in the project
}
No MISRA C:2012 Rules applicable to message 1501
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |