![]() |
![]() |
2004 | ![]() |
||||
![]() | |||||||
| Control flow | |||||||
No 'else' clause has been encountered following this 'if' ... 'else if' construct. This style is not permitted in some programming standards. An 'else' is considered important in the interests of logical completeness. Notice that message 2004 is only generated for an if statement without an 'else' clause, when the if is immediately preceded by the else keyword; otherwise, message 2000 is generated. For example:
/*PRQA S 1-9999 ++*/
/*PRQA S 2000, 2004 --*/
extern int gx;
extern int gy;
extern void foo1(int n)
{
if (n < 10)
{
++gx;
}
else if (n < 20) /* OK */
{
++gy;
}
else
{
}
}
extern void foo2(int n)
{
if (n < 10)
{
++gx;
}
else
{
if (n < 20) /* Message 2000 */
{
++gy;
}
}
}
extern void foo3(int n)
{
if (n < 10)
{
++gx;
}
else if (n < 20) /* Message 2004 */
{
++gy;
}
}
MISRA C:2012 Rules applicable to message 2004:
| Rule-15.7 (Required) | All if ... else if constructs shall be terminated with an else statement |
See also:
![]() | ||
| 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 |