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.eChecked automatically with code checker

Synopsis:Make sure all code in a switch statement serves a purpose.
Language:C
Severity Level:6
Category:Statement and Blocks


Description:

Justification

The code before the first "case" label can never be executed and clutters the program text.

Example 1

switch (i)
{
   int k = 0; /* WRONG: initializations are not possible */
   i = i + 1; /* this next statement is never executed */
case 1:                                
   /* any statement */
   break;
case 2:                                
   /* any statement */
   break;
default:
   {
      /* ... */
   }
}

Example 2

switch (i) /* A Switch with only one case. Better use if */
{
case 1:                                
   /* any statement */
   break;
default:
   {
      /* ... */
   }
}