Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 14.3 and null macros
#1
If a function is sometimes to be included and sometimes omitted, the classic solution is to define it like this:

Code:
#if FnIsWanted
  extern void Fn( void );
#else
  #define Fn( )
#endif

As already noted, this falls foul of rule 14.3, though primarily it is a breach of rule 19.4 (what a macro can be defined as).

I can get the the effect I want on my compiler without apparently breaching MISRA rules by using the following alternative:

Code:
#if FnIsWanted
  extern void Fn( void );
#else
  #define Fn( ) do{}while(0)
#endif

However, the body of this do-while is a null (compound) statement, so has my compiler missed a violation?
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)