Re: c++ operator << support for debug()()

From: Henrik Nordstrom <hno@dont-contact.us>
Date: 07 Jul 2003 16:08:50 +0200

mån 2003-07-07 klockan 14.43 skrev Robert Collins:

> Interestingly though, my testcases (in test-suite/debug.cc in the
> branch) use a trailing semicolon quite happily.

GCC most of the time accepts null statements (bare ;). Not sure what the
C/C++ standards say about null statements however, but I suspect it is
allowed as it is what you get if you define a empty macro replacement to
nullify a procedure call.

The do { .. } while(0) construct however forces the ; to be there,
making sure the syntax is uniform in all source which is good.

What I am not sure of however in this construct is the recursive use of
macros with overlapping arguments. I fear that this may fail with some
preprocessors.

Looking at the macro again. Why don't you move the data inside the
parantesis of the debugs() macro to clean this up? There is no variable
number of arguments when using streams formatting, so there is no
problem using a plain standard macro like this:

#define debugs(SECTION, LEVEL, OUTPUT) \
   do {
        if ((Debug::level = (LEVEL)) > Debug::Levels[SECTION]) { \
                Debug::getDebugOut() << CONTENT; \
                Debug::finishDebug(); \
        } \
   } while (/*CONSTCOND*/ 0)

and use it like

  debugs(x, y, a << b << c);

Regards
Henrik
Received on Mon Jul 07 2003 - 08:08:55 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:20:15 MST