Re: Debug statements



"Robbie Hatley" <see.my.signature@xxxxxxxxxxxxxxxxxxxx> writes:
[...]
What I do is use a function-like macro called "BLAT", defined
like so:

// In an included header file:
#ifdef BLAT_ENABLE
#define BLAT(X) printf ( X ) ;
#else
#define BLAT(X)
#endif

// In some source file:
#define BLAT_ENABLE
... some code...
BLAT("Length = %f and Height = %f\n", L, H)

After debugging, change "#define BLAT_ENABLE" to "#undef BLAT_ENABLE",
and the "BLAT" statements go away.

And if you maintain, expand, or refactor the code later, and it has
bugs, just #define BLAT_ENABLE and all your BLATs are re-activated.

That gives me complaints about passing too many arguments to BLAT. I
think you need to shift the parentheses from the macro definition to
the invocation, so it looks (to the preprocessor) like you're always
invoking BLAT with a single argument:

#ifdef BLAT_ENABLE
#define BLAT(X) printf X
#else
#define BLAT(X)
#endif

....

BLAT(("Length = %f and Height = %f\n", L, H));

Note that I've deleted the semicolon from the macro definition.

--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages