14-09-2011, 07:20 AM
If a function is sometimes to be included and sometimes omitted, the classic solution is to define it like this:
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:
However, the body of this do-while is a null (compound) statement, so has my compiler missed a violation?
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>