![]() |
![]() |
2016 | ![]() |
||||
![]() | |||||||
| Switch statements | |||||||
The 'default' clause in this 'switch' statement contains no executable code. Is this intended ? Coding standards often require that a 'default' clause should be included in every 'switch' statement as a defensive measure. A rule of this nature is unfortunately limited in its usefulness because an empty 'default' clause can easily be introduced as a way of satisfying the letter of the rule without serious consideration being given as to what action is appropriate. If an empty 'default' clause is intended, it may be wise to add suitable commentary to justify its existence. For example:
/*PRQA S 3227,3352,3408,3447 ++*/
extern int x;
extern void foo(int n)
{
switch (n)
{
case 1:
break;
default:
break; /* (An empty default clause should be commented) */
} /* Message 2016 */
switch (n)
{
case 1:
break;
default:
++x;
break;
} /* */
}
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |