[previous] MISRA C:2012  Rule-15.7:  (Required) [next] All if ... else if constructs shall be terminated with an else statement

Amplification:

A final else statement shall always be provided whenever an if statement is followed by a sequence of one or more else if constructs. The else statement shall contain at least either one side-effect or a comment.

Example Code:


#include "misra.h"
#include "m3cmex.h"

extern int16_t rule_1507( void )
{
   int16_t r = 0;

   if ( s16a == 2 )
   {
      r = 3;
   }
   else if ( s16a == 3 )                   /* 2004 */
   {
      r = 2;
   }

   return r;
}



QAC messages that encompass this guideline:

2004 No concluding 'else' exists in this 'if'-'else'-'if' statement.



(c) The Motor Industry Research Association, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents