home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15937 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  1.8 KB

  1. Path: sparky!uunet!mcsun!uknet!doc.ic.ac.uk!agate!spool.mu.edu!darwin.sura.net!sgiblab!munnari.oz.au!mel.dit.csiro.au!mineng.dmpe.CSIRO.AU!dmssyd.syd.dms.CSIRO.AU!metro!otc!swdev!grahamd
  2. From: grahamd@swdev.research.otca.oz.au (Graham Dumpleton)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Debugging output
  5. Message-ID: <6707@otc.otca.oz>
  6. Date: 8 Nov 92 00:28:16 GMT
  7. References: <spuler.720931050@coral> <Bx9369.3zL@cs.uiuc.edu> <Bx93Mr.42r@cs.uiuc.edu> <6706@otc.otca.oz>
  8. Sender: news@otc.otca.oz
  9. Organization: Technology Development Group, OTC Australia
  10. Lines: 42
  11.  
  12. In article <6706@otc.otca.oz>, grahamd@swdev.research.otca.oz.au (Graham Dumpleton) writes:
  13. > In article <Bx93Mr.42r@cs.uiuc.edu>, pjl@cs.uiuc.edu (Paul Lucas) writes:
  14. >   #ifdef DEBUG
  15. >   #define CDEBUG if (!debug) ; else cerr
  16. >   #else
  17. >   #define CDEBUG if (1) ; else cerr
  18. >   #endif
  19.  
  20. One further point about this, in optimising away the body of the 'else' when
  21. DEBUG isn't defined, cfront does not even parse and type check the code which
  22. is eliminated. For example, cfront wouldn't complain about debugstream being
  23. undefined in the following when DEBUG isn't defined
  24.  
  25.   #ifdef DEBUG
  26.   ofstream debugstream("debug");
  27.   #endif
  28.  
  29.   #ifdef DEBUG
  30.   #define CDEBUG if (!debug) ; else debugstream
  31.   #else
  32.   #define CDEBUG if (1) ; else debugstream
  33.   #endif
  34.  
  35.   ...
  36.  
  37.   CDEBUG << "hello world" << endl;
  38.  
  39. If this approach is used it may not be wise to rely on this to occur for all
  40. compilers though so you may be better off writing
  41.  
  42.   #ifdef DEBUG
  43.   #define CDEBUG if (!debug) ; else debugstream
  44.   #else
  45.   #define CDEBUG if (1) ; else cerr
  46.   #endif
  47.  
  48. I would be interested to hear what other C++ compilers do in this situation,
  49. ie. do they actually check the code which is eliminated.
  50.  
  51. -- 
  52. Graham Dumpleton (grahamd@swdev.research.otca.oz.au)
  53.