Xref: utzoo comp.lang.c:28464 comp.unix.wizards:21813 alt.sources:1841 comp.sources.d:5270 misc.misc:9673 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!zds-ux!bjstaff From: bjstaff@zds-ux.UUCP (Brad Staff) Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc Subject: Re: #define DEBUG... (using printf for debugging) Message-ID: <301@zds-ux.UUCP> Date: 4 May 90 19:04:18 GMT References: <11290@hoptoad.uucp> <40628@cornell.UUCP> Followup-To: comp.unix.wizards Organization: Zenith Data Systems Lines: 24 I add some declarations that look something like the following: #ifdef PRODUCTION #define DEBUG 0 #else int DEBUG = FLAG1 | FLAG2 | ... | FLAGn; #endif /* PRODUCTION */ Then I do it like this: if (DEBUG & FLAGx) printf(...); This way the debug statements look more like regular C code, which is more aesthetically pleasing to my eyes. :-) This method allows you to turn debug printfs on and off in a running system by patching the DEBUG variable with a kernel debugger or adb. When you #define PRODUCTION, any compiler worth using (IMHO) will optimize away both the test and the printf itself, for a zero performance penalty. -- Brad Staff | Zenith Data Systems | "A government that can forbid certain 616-982-5791 | psychoactive drugs can mandate others." bjstaff@zds-ux.zds.com | - Russell Turpin