Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2004-13.5

In this section:
Synopsis

(Required) The three expressions of a for statement shall be concerned only with loop control.

Enabled by default

Yes

Severity/Certainty

High/Medium

highmedium.png
Full description

A for loop counter variable is not initialized in the for loop.

Coding standards
MISRA C:2004 13.5

(Required) The three expressions of a for statement shall be concerned only with loop control.

Code examples

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

int example(void) {
  int i, x = 10;

  /* 'i' used as a counter, not initialized */
  for ( ; i < 10; i++) {
    x++;
  }
  
  return x;
}

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

int example(void) {
  int i, x = 10;

  /* 'i' initialized in loop header */
  for (i = 0; i < 10; i++) {
    x++;
  }
  
  return x;
}