Ben Bacarisse <be********@bsb.me.ukwrites:
vivek <gv********@gmail.comwrites:
> i have used some debug macro and called several times(hundreds) in
the code.
The purpose of the macro was to print the values at that time to the
screen
Now that i have finished debugging, i do not want to execute the
macro.
If i use
#define DEBUG1 <blank>
the code executes the statements inside the debug except that it is
not printing on the screen, which takes time.
Is there any better way(than commenting all hundreds of lines of
code)?
It may be too late now, but one way is to use extra parentheses:
#define DEBUG(x) logging_function x
and in the code:
DEBUG(("x = %d\n", x));
so when you need to get rid of all the code you define:
#define DEBUG(x)
and you get nothing at all.
That's necessary only if DEBUG takes a variable number of arguments
(say, if it's a wrapper for fprintf).
Suppose DEBUG1 takes a single argument, and a typical call is
DEBUG1(some_expression);
Then this:
#define DEBUG1
causes the call to be replaced with
(some_expression);
which still evaluates the expression. But this:
#define DEBUG1(arg)
makes DEBUG1 a function-like macro, so the call is replaced with just this:
;
If you have several DEBUG*() macros taking various fixed numbers of
arguments, you can define an empty function-like macro for each. If
DEBUG() is variadic, you might be able to use a C99 variadic macro
definition *if* your compiler supports it (or supports an extension
that does something similar); I'm not familiar enough with that C99
feature to comment further.
If you actually need to make several hundred changes to your source
code, some of the more advanced features of your favorite text editor
or scripting language might be helpful. Of course that's a topic for
another newsgroup.
--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"