home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1271 < prev    next >
Internet Message Format  |  1990-12-28  |  1KB

  1. From: bjstaff@zds-ux.UUCP (Brad Staff)
  2. Newsgroups: comp.lang.c,comp.unix.wizards,alt.sources,comp.sources.d,misc.misc
  3. Subject: Re: #define DEBUG... (using printf for debugging)
  4. Message-ID: <301@zds-ux.UUCP>
  5. Date: 4 May 90 19:04:18 GMT
  6.  
  7. I add some declarations that look something like the following:
  8.  
  9. #ifdef    PRODUCTION
  10. #define    DEBUG    0
  11. #else
  12. int    DEBUG = FLAG1 | FLAG2 | ... | FLAGn;
  13. #endif    /* PRODUCTION */
  14.  
  15. Then I do it like this:
  16.  
  17.     if (DEBUG & FLAGx)
  18.         printf(...);
  19.  
  20. This way the debug statements look more like regular C code, which is more
  21. aesthetically pleasing to my eyes.  :-)  This method allows you to turn debug
  22. printfs on and off in a running system by patching the DEBUG variable with a
  23. kernel debugger or adb.  When you #define PRODUCTION, any compiler worth using
  24. (IMHO) will optimize away both the test and the printf itself, for a zero
  25. performance penalty.
  26. -- 
  27. Brad Staff               |
  28. Zenith Data Systems      | "A government that can forbid certain
  29. 616-982-5791             |  psychoactive drugs can mandate others."
  30. bjstaff@zds-ux.zds.com   |    - Russell Turpin
  31.