[previous] MISRA C:2012  Rule-16.5:  (Required) [next] A default label shall appear as either the first or the last switch label of a switch statement

Example Code:


#pragma PRQA_MESSAGES_OFF 2982

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

extern int16_t rule_1605( void )
{
   int16_t x;

   switch ( s16a )
   {
   default:                     /* 2009 */              /* Compliant */
      x = 7;
      break;
   case 2:
      x = 5;
      break;
   case 3:
      x = 2;
      break;
   }

   switch ( s16a )
   {
   case 2:
      x = 5;
      break;
   default:                     /* 2009 */              /* Not Compliant */
      x = 7;
      break;
   case 3:
      x = 2;
      break;
   }

   return x;
}


QAC messages that encompass this guideline:

2009 This 'default' label is not the final 'case' label within the 'switch' block.



(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