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
#2
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.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)