Xref: utzoo comp.lang.c:28388 comp.unix.wizards:21766 alt.sources:1824 comp.sources.d:5245 misc.misc:9651 Path: utzoo!mnetor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!snorkelwacker!mit-eddie!uw-beaver!cornell!gordon From: gordon@mimir.cs.cornell.edu (Jeffrey Adam Gordon) Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc Subject: #define DEBUG... (using printf for debugging) Message-ID: <40628@cornell.UUCP> Date: 3 May 90 14:50:35 GMT References: <11290@hoptoad.uucp> Sender: nobody@cornell.UUCP Reply-To: gordon@cs.cornell.edu (Jeffrey Adam Gordon) Organization: Cornell Univ. CS Dept, Ithaca NY Lines: 48 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? I have though of doing the following (which is not very elegant but I thought it would work): #ifdef DODEBUG # define DEBUG printf # define ENDDEBUG ; #else # define DEBUG /* # define ENDDEBUG */ #endif DODEBUG which would allow the following syntax for debugging DEBUG ("the value is %d", val); ENDDEBUG Unfortunately, I can't figure out how to #define something to be equal to "/*" sinece "/*" always seems to be interpreted as the start of a comment. Well, I've been rambling trying to describe the problem. Basically, does anyone have an idea how I can do the above easily and elegantly? Thanks for reading. - Jeff