Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-8.9_b

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

lowmedium.png
Full description

A global object was found that is only referenced from a single function. This check is identical to MISRAC2004-8.7.

This is a link analysis check.

Coding standards
MISRA C:2004 8.7

(Required) Objects shall be defined at block scope if they are only accessed from within a single function.

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());
}