[previous] 2008 [next] Code statements precede the first label in this 'switch' construct.
Redundancy REFERENCE - ISO:C90-6.6.4.2 The switch Statement - Semantics

An executable statement has been located before the first case label in this switch statement. This is unreachable code and the statement will never be executed.

Declarations are the only form of meaningful code that can precede the first case label but any attempted initialization will simply be ignored.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 2008, 2880, 2882, 3234 --*/

extern int n;

void foo(int m)
{
    switch (m)        /* Message 2882 */
    {
        int j;        /* Message 3234 */
        int k = 2;
        n = n + 1;    /* Message 2008 and 2880 */

    case 1:
        --n;
        break;

    default:
        ++n;
        break;
    }
}


MISRA C:2012 Rules applicable to message 2008:

Rule-16.1  (Required) All switch statements shall be well-formed


See also:

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