Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-16.4

In this section:
Synopsis

(Required) Every switch statement shall have a default label

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Switch statements without a default clause were found.

Coding standards
CWE 478

Missing Default Case in Switch Statement

MISRA C:2012 Rule-16.4

(Required) Every switch statement shall have a default label

Code examples

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

int example(int x) {
  switch(x){
  }
}

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

int example(int x) {
  switch(x){
    case 3:
      return 0;
      break;
    case 5:
      return 1;
      break;
    default:
      return 2;
      break;
  }
}