![]() |
![]() |
2003 | ![]() |
||||
![]() | |||||||
| Switch statements | |||||||
The preceding non-empty case clause is not terminated with a jump statement. Is this intended ? It is very easy to overlook "fall-through" situations such as this when reviewing 'switch' statements. If this is the intended behaviour, it is advisable to insert a comment in order to confirm the intention. Message 2003 is generated whenever a 'case' label is preceded by a clause which is not terminated with either a 'break', a 'return', a 'continue' or a 'goto' statement. For example:
/*PRQA S 2017,3120,3227,3408 ++*/
extern int foo(int value)
{
int r = 2;
switch (value)
{
case 1:
r = 10;
case 2: /* Message 2003 */
++r;
break;
case 3: /* Empty clause - fall through allowed */
case 4:
r = 20;
break;
default:
r = 30;
break;
}
return r;
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |