MISRA Discussion Forums

Full Version: Rule 14.3 and null macros
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
MISRA C uses the term "null statement" in the same way as the standard, namely a statement consisting of nothing but a semicolon character. The body of the while loop is an empty compound statement but it's not syntactically a null statement. Therefore the checker is correct not to report a violation of Rule 14.3.