[previous] 2019 [next] 'Switch' label is located within a nested code block.
Switch statements

This switch case label is located in this switch statement within a nested block. This is not illegal syntax, but is it really intended ?!

The C language allows for great freedom in the way that a switch statement can be constructed; but locating a case statement in this way is almost certainly a mistake.

For example:


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

extern int foo(int i, int p)
{
    int ret = p;

    switch (i)
    {
    case 0:
        if (ret > 2)
        {

        case 1:                     /* Message 2019 */
            ret = 2;
            break;
        }
        break;

    case 2:
        ret = 3;
        break;

    default:
        ret = 4;
        break;
    }

    return ret;
}


MISRA C:2012 Rules applicable to message 2019:

Rule-16.2  (Required) A switch label shall only be used when the most closely-enclosing compound statement is the body 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