[previous] MISRA-C:2004  Rule  15.1:  (Required) [next] A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
The scope of a case or default label shall be the compound statement, which is the body of a switch statement. All case clauses and the default clause shall be at the same scope.

Example Code:


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

extern S16 test_1501( void )
{
   switch ( s16a )
   {
   case 0:

      if ( s16b == 1 )
      {
         case 1:                /* MISRA Violation */
            break;
      }

      while ( s16b < 10 )
      {
         ++s16b;
         case 2:
            break;
      }
   default:
      break;
   }

   return 1;
}


QAC messages that encompass this guideline:

2019 'Switch' label is located within a nested code 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