[previous] 2009 [next] This 'default' label is not the final 'case' label within the 'switch' block.
Switch statements

This 'default' clause is not the final clause in the switch statement. This is quite legal but rather unconventional.

For example:


/*PRQA S 2017,3120,3227,3408 ++*/

extern int foo(int n)
{
    int r;

    switch (n)
    {
    default:                            /* Message 2009 */
        r = 0;
        break;

    case 1:
        r = 5;
        break;

    case 3:
        r = 10;
        break;

    case 5:
        r = 20;
        break;
    }

    return r;
}


MISRA C:2012 Rules applicable to message 2009:

Rule-16.5  (Required) A default label shall appear as either the first or the last switch label of a switch statement


QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents