Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2023-9.5.1_b (C++ only)

In this section:
Synopsis

(Advisory) Legacy for statements should be simple

Enabled by default

No

Severity/Certainty

Low/High

lowhigh.png
Full description

A for condition shall only compare loop counter to a loop bound using a relational operator. The loop bound variable must also be of the same type or have a constant value that can be reached. Note that breaking 9.5.1_a is likely to break this check if the loop counter is not compliant.

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:

bool is_less(int a , int b);

void example(int n) {
  for (int i; is_less(i, n); ++i) {} // Non-Compliant
}

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

void example(int n) {
  for (int i; i < n; ++i) {} // Compliant
}