MISRAC2012-Rule-8.9_a
In this section:
Synopsis
(Advisory) An object should be defined at block scope if its identifier only appears in a single function.
Enabled by default
No
Severity/Certainty
Low/Medium

Full description
A global object was found that is only referenced from a single function.
Coding standards
- MISRA C:2012 Rule-8.9
(Advisory) An object should be defined at block scope if its identifier only appears in a single function
Code examples
The following code example fails the check and will give a warning:
static int i = 10; // this object is only used inside the example function
int example(void) {
return i;
}
void main() {
printf("example() = %d\n", example());
}
The following code example passes the check and will not give a warning about this issue:
int example(void) {
int i = 10; // this object is only used inside the example function
return i;
}
void main() {
printf("example() = %d\n", example());
}