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

SR:  9.4.2#1Checked automatically with code checker

Synopsis:All switch statements shall have a default clause, even if that clause is empty.
Language:C
Severity Level:3
Category:STATEMENTS


Description:
Defensive programming dictates that multiple choice constructs have a guard condition, to trap “impossible” errors.

Example:

switch( a )
{
    case 'a':
    case 'b':
        break;
    case 'c':
        j = 4;
    case 'd':
} /* WRONG - no default clause */

Example:

switch( a )
{
    case 'a':
    case 'b':
        break;
    case 'c':
        j = 4;
    case 'd':
    default:
        ;
} /* RIGHT - default case */