Skip to main content

IAR Embedded Workbench for Arm 9.70.x

EXP-null-stmt

In this section:
Synopsis

The body of an if, while, or for statement is a null statement.

Enabled by default

No

Severity/Certainty

Low/High

lowhigh.png
Full description

The body of an if, while, or for statement is a null statement. This might be intentional (a placeholder), but because a null statement as the body is difficult to find when debugging or reviewing code, it is good practice to use an empty block to identify a stub body. Note that if the condition expression of a for loop has possible side-effects, or if an if statement has a null body but carries an else clause, this check will not give a warning.

Coding standards
CERT EXP15-C

Do not place a semicolon on the same line as an if, for, or while statement

CWE 483

Incorrect Block Delimitation

Code examples

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

void example(void) {
  int i;
  for (i=0; i!=10; ++i);  //Null statement as the
                          //body of this for loop
}

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

void example(void) {
  int i;
  for (i=0; i!=10; ++i){  //An empty block is much
  }                       //more readable
}