![]() |
![]() |
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;
} /* */
}
No MISRA C:2012 Rules applicable to message 2016
![]() | ||
| 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 |