TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
ASML C Coding Standard
Search

Rule:  6.8.4.2.aChecked automatically with code checker

Synopsis:The switch expression shall not contain any logical expression (one or more of the ">", ">=", "<", "<=", "==", "!=", "&&", "||" or "!" operators).
Language:C
Severity Level:5
Category:Statement and Blocks


Description:

Justification

Using relational or logical operators in a "switch" expression is very likely to be wrong and is at best confusing. Consider the use of an "if" statement.

Example

#define CCBB_THE_CHOICE 1
switch (option == pick) /* WRONG */
{
case CCBB_THE_CHOICE:
   /* any statement */
   break;
default:
   /* any statement */
   break;
}