Xref: utzoo comp.lang.c:28405 comp.unix.wizards:21777 alt.sources:1828 comp.sources.d:5253 misc.misc:9656 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!mstar!karl From: karl@MorningStar.Com (Karl Fox) Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <1990May3.200216.3705@MorningStar.COM> Date: 3 May 90 20:02:16 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> Sender: news@MorningStar.COM (USENET Administrator) Reply-To: karl@MorningStar.Com (Karl Fox) Organization: Morning Star Technologies Lines: 38 In-Reply-To: gordon@mimir.cs.cornell.edu's message of 3 May 90 14:50:35 GMT In article <40628@cornell.UUCP> gordon@mimir.cs.cornell.edu (Jeffrey Adam Gordon) writes: I want to have a DEBUG flag which controls whether diagnostic printfs are executed or not. The obvious way to do this is: #ifdef DEBUG printf ("debugging information"); #endif DEBUG But its a pain to have to type the #ifdef ... #endif all the time, and its less readable than simply having: DEBUG ("debugging information"); Now, I can use the latter format if I #define DEBUG printf but then how do I turn DEBUG off? Here is a not-too-gross method I have seen suggested (and used): # define DEBUG(a) printf a or, to disable it, # define DEBUG(a) Then, call it with a double set of outer parentheses: DEBUG(("Warning: user %s has an ugly face!\n", user_name)); It even works as the THEN clause of an IF statement. -- Karl Fox, Morning Star Technologies karl@MorningStar.COM