Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2023-6.7.1 (C++ only)

In this section:
Synopsis

(Required) Local variables shall not have static storage duration

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found non-const variable with static storage duration

Coding standards

This check does not correspond to any coding standard rules.

Code examples

The following code example fails the check and will give a warning:

int example() {
  static int count = 0;
  return ++count;
}

The following code example passes the check and will not give a warning about this issue:

static int count = 0; // Violates other rules though

int example() {
  return ++count;  
}