#define DEBUG... (using printf for debugging)

Wm E. Davidsen Jr davidsen at sixhub.UUCP
Fri May 4 10:38:46 AEST 1990


In article <40628 at cornell.UUCP> gordon at cs.cornell.edu (Jeffrey  Adam Gordon) writes:
| I want to have a DEBUG flag which controls whether diagnostic printfs
| are executed or not.

#ifdef	DEBUG
#undef DEBUG /* prevent warning from redef */
#define DEBUG(x) printf x
#else
#define DEBUG(x)
#endif

To use:

	DEBUG(("Any # of args: %d\n", whatever));

  The secret is in having the 2nd level of parens in the invocation of
DEBUG and no parens in the expansion. Works like a charm!
-- 
bill davidsen - davidsen at sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list