[previous] 1460 [next] 'Switch' label value, %s, not contained in enum type.
Switch statements REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers

The controlling expression of this switch statement is of enum type but the value of this case expression is not consistent with any of the constants in the enumeration.

It is quite possible to store arbitrary values within an enum object but this would only happen as a result of a mistake or some very bad practice. This case label will therefore be unreachable under normal circumstances.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 1460, 1470 --*/

enum SIZE { small,  medium,  large };

int paint (enum SIZE box)
{
    switch (box)
    {
    case small:
        return 10;

    case 1:                             /* Message 1470 */
        return 30;

    case 5:                             /* Message 1460 and 1470 */
        return 20;

    default:
        return 0;
    }
}


MISRA-C:2004 Rules applicable to message 1460:

Rule  14.1  (Required) There shall be no unreachable code.


See also:

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