Preprocessor macros: how to insert arguments?

Posted by mhambra on Stack Overflow See other posts from Stack Overflow or by mhambra
Published on 2011-01-01T23:23:47Z Indexed on 2011/01/01 23:53 UTC
Read the original article Hit count: 398

Filed under:
|
|

Hi all,

the code has a number of following sections:

int filter;
#ifdef INPUTFILTER_FOO
 LOG4CXX_DEBUG(log, "FOO filter used");
         filter = F_FOO;
#endif

They are used multiple times in the code (used to provide I/O, threading support etc for all testing configurations), Circa they are essential for debugging but make the code look harsh, want to replace them with macros, one for each category_type namespace.

So, want to expand the following:

MACROSTUFFBAZ(log2, stuff, "BAZ") <- the text part is unique for each class, so it needs to be included in macro too.

to:

#ifdef INPUTSTUFF_BAZ
  LOG4CXX_DEBUG(log2, "BAZ stuff used");
  stuff = S_BAZ;
#endif

To define macros, plan to use this:

debug.hpp:

   #ifdef INPUTSTUFF_BAZ
    #define MACROSTUFFBAZ ...
   #else
   #define MACROSTUFFBAZ
    .. no code!
   #endif
  #endif

(at least this will give a clear overview of the things currently undergoing probation, without seeing them around the code)

© Stack Overflow or respective owner

Related posts about c++

Related posts about macros