Xref: utzoo comp.lang.c:28420 comp.unix.wizards:21784 alt.sources:1831 comp.sources.d:5258 misc.misc:9662 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!crdgw1!sixhub!davidsen From: davidsen@sixhub.UUCP (Wm E. Davidsen Jr) Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <908@sixhub.UUCP> Date: 4 May 90 00:38:46 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> Reply-To: davidsen@sixhub.UUCP (bill davidsen) Followup-To: comp.lang.c Organization: *IX Public Access UNIX, Schenectady NY Lines: 22 In article <40628@cornell.UUCP> gordon@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@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