Re: Debug statements
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 03 Apr 2008 14:12:51 -0700
"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"
.
- Follow-Ups:
- Re: Debug statements
- From: Robbie Hatley
- Re: Debug statements
- References:
- Debug statements
- From: vivek
- Re: Debug statements
- From: Robbie Hatley
- Debug statements
- Prev by Date: Re: Fedup with SPAM
- Next by Date: Re: Is it possible to have two main functions in a c program?
- Previous by thread: Re: Debug statements
- Next by thread: Re: Debug statements
- Index(es):
Relevant Pages
|