Xref: utzoo comp.lang.c:28406 comp.unix.wizards:21778 alt.sources:1829 comp.sources.d:5254 misc.misc:9657 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!mindcrf.UUCP!ronnie From: ronnie@mindcrf.UUCP (Ronnie Kon) Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <9005032204.AA11912@mindcrf.mindcraft.com> Date: 3 May 90 22:04:46 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> Sender: daemon@ucbvax.BERKELEY.EDU Followup-To: comp.lang.c Organization: Mindcraft, Inc. Lines: 31 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. > [ lots of stuff deleted ] How about: #if WANT_DEBUGGING # define DEBUG(a,b,c,d,e) printf(a,b,c,d,e) #else # define DEBUG(a,b,c,d,e) #endif This is ugly, in that you must always supply a fixed number of parameters, but it's quick and easy. You can also use multiple definitions, DEBUG1, DEBUG2, etc, each taking a different number of parameters. If your application is not real-time, you can also make DEBUG a real routine, which does nothing if your definition is not turned on, and a printf if it is. This causes an overhead of a few microseconds on an average machine (say a 10MHz 68000) each call. Hope this helps. Ronnie -- ------------------------------------------------------------------------------- Ronnie B. Kon | "The answers to life's problems aren't at kon@mindcraft.com | the bottom of a bottle: they're on TV!" ...!{decwrl,ames}!mindcrf!ronnie | -- Homer Simpson -------------------------------------------------------------------------------