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

  1. From: davidsen@sixhub.UUCP (Wm E. Davidsen 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: <908@sixhub.UUCP>
  5. Date: 4 May 90 00:38:46 GMT
  6.  
  7. In article <40628@cornell.UUCP> gordon@cs.cornell.edu (Jeffrey  Adam Gordon) writes:
  8. | I want to have a DEBUG flag which controls whether diagnostic printfs
  9. | are executed or not.
  10.  
  11. #ifdef    DEBUG
  12. #undef DEBUG /* prevent warning from redef */
  13. #define DEBUG(x) printf x
  14. #else
  15. #define DEBUG(x)
  16. #endif
  17.  
  18. To use:
  19.  
  20.     DEBUG(("Any # of args: %d\n", whatever));
  21.  
  22.   The secret is in having the 2nd level of parens in the invocation of
  23. DEBUG and no parens in the expansion. Works like a charm!
  24. -- 
  25. bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
  26.     sysop *IX BBS and Public Access UNIX
  27.     moderator of comp.binaries.ibm.pc and 80386 mailing list
  28. "Stupidity, like virtue, is its own reward" -me
  29.