[previous] MISRA-C:2004  Rule  15.3:  (Required) [next] The final clause of a switch statement shall be the default clause.
The requirement for a final default clause is defensive programming. This clause shall either take appropriate action or contain a suitable comment as to why no action is taken.

Example Code:


#include "misra.h"
#include "m2cmex.h"

extern S16 test_1503( void )
{
   S16 x = 0;

   switch ( s16a )
   {
   case 0:
      x = 2;
      break;
   case 1:
      x = 1;
      break;
   }                            /* MISRA Violation */

   switch ( s16b )
   {
   default:                     /* MISRA Violation */
      x = 7;
      break;
   case 2:
      x = 5;
      break;
   case 3:
      ++x;
      break;
   }

   return x;
}


QAC messages that encompass this guideline:

2002 No 'default' label found in this 'switch' statement.
2009 This 'default' label is not the final 'case' label within the 'switch' block.



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