#include typedef _Bool bool_t; extern void f ( void ); extern void g ( void ); extern void h ( void ); void wrapAround ( void ) { uint16_t x; /* ----------------- Example code from MISRA C:2012 begin ----------------- */ #define BASE 65024u switch ( x ) { case BASE + 0u: f ( ); break; case BASE + 1u: g ( ); break; case BASE + 512u: /* Non-compliant */ h ( ); break; } /* ------------------ Example code from MISRA C:2012 end ------------------ */ } /* ----------------- Example code from MISRA C:2012 begin ----------------- */ #if 1u + ( 0u - 10u ) /* Non-compliant */ /* ------------------ Example code from MISRA C:2012 end ------------------ */ #endif /* ----------------- Example code from MISRA C:2012 begin ----------------- */ #define DELAY 10000u #define WIDTH 60000u void fixed_pulse ( void ) { uint16_t off_time16 = DELAY + WIDTH; /* Non-compliant */ } const uint16_t c = 0xffffu; void f ( void ) { uint16_t y = c + 1u; /* Compliant */ } bool_t b; void g ( void ) { uint16_t x = ( 0u == 0u ) ? 0u : ( 0u - 1u ); /* Compliant */ uint16_t y = b ? 0u : ( 0u - 1u ); /* Non-compliant */ } /* ------------------ Example code from MISRA C:2012 end ------------------ */