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

  1. From: fenske@dfsun1.electro.swri.edu (Robert Fenske Jr)
  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: <1521@dfsun1.electro.swri.edu>
  5. Date: 8 May 90 13:11:17 GMT
  6.  
  7. In article <801@oz.rci.dk> kc@oz.rci.dk (Knud Christensen) writes:
  8. >gordon@mimir.cs.cornell.edu (Jeffrey  Adam Gordon) writes:
  9. >
  10. >>I want to have a DEBUG flag which controls whether diagnostic printfs
  11. >>are executed or not.
  12. >
  13. How 'bout this:
  14.  
  15. #define DPRINTF(s)    if (DEBUG) printf(s)
  16.  
  17. which can't be used in "if" statements for example--but still useful--or
  18. this:
  19.  
  20. #define DPRINTF(s)    (DEBUG ? printf(s) : 0)
  21.  
  22. with perhaps some compilers complaining about a useless statement when
  23. debug is zero.  DEBUG could be a #define or a variable and can be easily
  24. taken care of on the compiler command line.
  25.  
  26. -- 
  27. Robert Fenske, Jr.                      Sw     | The Taming the C*sm*s series:
  28. Electromagnetics Division              /R---\  |
  29. Southwest Research Institute          | I    | | "The Martian canals were the
  30. dfsun1.electro.swri.edu 129.162.160.4  \----/  |  Martians' last ditch effort."
  31.