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

Guideline:  9.4.2#3Checked automatically with code checker

Synopsis:The default clause should be the last entry in the switch statement.
Language:C
Severity Level:4
Category:STATEMENTS


Description:
Since the default action is a “catch-all” it aids the reader to enumerate the possible special cases before the general case.

Example:

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

Example:

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