#define DEBUG... (using printf for debugging)
Randy Hutson
randy at csseq.cs.tamu.edu
Fri May 4 07:15:43 AEST 1990
In article <40628 at cornell.UUCP> gordon at cs.cornell.edu (Jeffrey Adam Gordon) wri
tes:
>I want to have a DEBUG flag which controls whether diagnostic printfs
>are executed or not.
I use something like the following:
#ifdef DEBUG
#define DPRINTF printf
#else
#define DPRINTF if(0) printf
#endif
Now there's no need to put an extra set of parentheses about DPRINTF's
arguments. As for any efficiency concerns, no compiler I regularly
use (gcc, Sequent cc, and sun cc) generates an explicit comparison
to 0. However, they do leave in the dead code (calls to printf) unless
the optimizer is invoked, so this method could make your executables
larger if your C compiler doesn't have an optimizer which eliminates
dead code.
More information about the Comp.lang.c
mailing list