![]() |
![]() |
1472 | ![]() |
||||
![]() | |||||||
| Switch statements | REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers | ||||||
An enum constant is being used as a case label in a switch statement with a controlling expression of a different enum type. The C language allows this but it is probably a mistake. If the value happens to correspond to an enum constant in the "correct" enum type, it would be better to use that constant instead. If it doesn't, the case statement will be unreachable under normal circumstances and message 1460 will be generated. For example:
/*PRQA S 1-9999 ++*/
/*PRQA S 1472, 1460, 1470 --*/
enum SIZE { SMALL = 2, MEDIUM = 4, LARGE = 6 };
enum COLOUR { RED = 4, WHITE = 5, BLUE = 6 };
extern void paint ( enum SIZE box )
{
switch (box)
{
case 1: /* Message 1470 + 1460 */
break;
case 2: /* Message 1470 */
break;
case MEDIUM:
break;
case WHITE: /* Message 1472 + 1460 */
break;
case BLUE: /* Message 1472 */
break;
default:
break;
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |