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#2Checked automatically with code checker

Synopsis:Each case clause and default clause shall be terminated by a break statement unless empty.
Language:C
Severity Level:2
Category:STATEMENTS


Description:
Allowing case clauses to fall-through into each other is a confusing practice - if two (or more) clauses share common tail code, that should be made explicit by making the tail code a function and calling it from each of the clauses that requires it.

Example:

switch( a )
{
    case 'c':
        j = 4;
    case 'd': /* WRONG - non-empty and no break. */
}

Example:

switch( a )
{
    case 'a': /* RIGHT - empty case */
    case 'b':
        break; /* RIGHT - break following */
}