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

  1. From: thornley@cs.umn.edu (David H. Thornley)
  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: <1990May3.192347.12973@cs.umn.edu>
  5. Date: 3 May 90 19:23:47 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. >The obvious way to do this is:
  12. >
  13. >#ifdef DEBUG
  14. >    printf ("debugging information");
  15. >#endif DEBUG
  16.  
  17. How about
  18. #ifdef DEBUG
  19. #define D(X) X
  20. #else
  21. #define D(X)
  22. #endif
  23.  
  24. and 
  25. D(printf("debugging information\n");)
  26.  
  27. If DEBUG is defined, anything in D() is used as is; if not, anything in
  28. D() is disregarded.  It seems to work for me.
  29.  
  30. David Thornley
  31.