Skip to main content

IAR Embedded Workbench for RISC-V 3.40

CERT-EXP19-C

In this section:
Synopsis

No braces for the body of an if, for, or while statement

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

The body of an if, for, or while statement is missing opening and closing braces. Opening and closing braces for if, for, and while statements should always be used even if the statement's body contains only a single statement

Coding standards
CERT EXP19-C

Use braces for the body of an if, for, or while statement

Code examples

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

void example(void) {
  int login;

  if (invalid_login())
    login = 0;
  else
    login = 1;
}

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

#define ADMINISTRATOR 0
#define GUEST 1

void example(void) {
  int privileges;

  if (invalid_login()) {
    if (allow_guests()) {
      privileges = GUEST;
    }
  } else {
    privileges = ADMINISTRATOR;
  }
}