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 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