[previous] MISRA-C:2004  Rule  15.5:  (Required) [next] Every switch statement shall have at least one case clause.
For example:

switch ( x )
{
    uint8_t var;        /* not compliant - decl before 1st case     */
case 0:
    a = b;
    break;              /* break is required here                   */
case 1:                 /* empty clause, break not required         */
case 2:
    a = c;              /* executed if x is 1 or 2                  */
    if ( a == b )
    {
        case 3:         /* Not compliant - case is not allowed here */
    }
    break;              /* break is required here                   */
case 4:
    a = b;              /* Not compliant - non empty drop through   */
case 5:
    a = c;
    break;
default:                /* default clause is required               */
    errorflag = 1;      /* should be non-empty if possible          */
    break;              /* break is required here, in case a
                           future modification turns this into a
                           case clause                              */
}


QAC messages that encompass this guideline:

3315 This 'switch' statement contains only a single path - it is redundant.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents