Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA switch staement
#3
An example of a compliant switch statement is:
Code:
typedef signed char int8_t;
extern void use_int8(int8_t i);

void R_16_1 ( int8_t input )
{
    switch ( input )
    {
       case 0:
       {
          use_int8 ( input );
          break;
       }
       case 1:
          /* { .. } not required at this level */
          use_int8 ( -input );
          break;
          
       default:
       {
          use_int8 ( 0 );          
          break;
       }
    }
}
Other compliant examples can be seen in the example sections of rules 16.4, 16.5, and 16.6 in the MISRA C:2012 guidelines.
Posted by and on behalf of the MISRA C Working Group


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)