MISRA.SWITCH.WELL_FORMED.DEFAULT.FIRST_OR_LAST.2012A default label shall appear as either the first or the last switch label of a switch statement.
MISRA C 2012 Rule 16.5: A default label shall appear as either the first or the last switch label of a switch statementCategory: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 RationaleThis rule makes it easy to locate the default label within a switch statement.Exampleswitch ( x ) { default: /* Compliant - default is the first label */ case 0: ++x; break; case 1: case 2: break; } switch ( x ) { case 0: ++x; break; default: /* Non-compliant - default is mixed with the case labels */ x = 0; break; case 1: case 2: break; } switch ( x ) { case 0: ++x; break; case 1: case 2: break; default: /* Compliant - default is the final label */ x = 0; break; } See alsoRule 15.7, Rule 16.1 |