Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2008-6-4-7

In this section:
Synopsis

(Required) The condition of a switch statement shall not have bool type.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A switch expression was found that represents a value that is effectively Boolean. This check is identical to MISRAC2004-15.4, MISRAC2012-Rule-16.7.

Coding standards
MISRA C:2004 15.4

(Required) A switch expression shall not represent a value that is effectively boolean.

MISRA C:2012 Rule-16.7

(Required) A switch-expression shall not have essentially Boolean type

Code examples

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

void example(int x) {
	switch(x == 0) {
		case 0:
		case 1:
		default:
	}
}

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

void example(int x) {
	switch(x) {
		case 1:
		case 0:
		default:
	}
}