Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2012-Rule-14.1_b

In this section:
Synopsis

(Required) A loop counter shall not have essentially floating type

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A variable of essentially float type that is used in the loop condition, is then modified in the loop body. This check is identical to CERT-FLP30-C_b.

Coding standards
CERT FLP30-C

Do not use floating point variables as loop counters

MISRA C:2012 Rule-14.1

(Required) A loop counter shall not have essentially floating type

Code examples

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

void example(void) {
  int a = 10;
  float f = 0.001f;

  while (f < 1.00f) {
    f = f + (float) a;
    a++;
  }
}

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

void example(void) {
  int a = 10;
  float f = 0.001f;

  while (a < 30) {
    f = f + (float) a;
    a++;
  }
}