Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2004-8.7

In this section:
Synopsis

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

Enabled by default

Yes

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 MISRAC2012-Rule-8.9_b.

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;
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;
  return i;
}
void main() {
  printf("example() = %d\n", example());
}