Skip to main content

IAR Embedded Workbench for RX 5.20

Detecting unhandled cases in switch statements

In this section:
Description

Checks for a missing case label in a switch statement that does not have a default label.

Why perform the check

The check is useful, for example, to detect when an enum type has been augmented with a new value that is not yet handled in a switch statement.

How to use it

Compiler option: ‑‑runtime_checking switch

In the IDE: Project>Options>Runtime Checking>Switch

The check can be applied to one or more modules.

The check can be avoided by adding a default label.

How it works

The compiler inserts an implicit default label to perform the check in each switch statement that does not have a default label.

Example

Follow the procedure described in Getting started using C-RUN runtime error checking, but use the Switch option.

This is an example of source code that will be identified during runtime:

crs_switch_Hom7.1_M16_1.PNG

C-RUN will report Unhandled case in switch. This is an example of the message information that will be listed:

message_switch_Hom7.1_M16_1.PNG