home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15825 < prev    next >
Encoding:
Text File  |  1992-11-05  |  2.2 KB  |  73 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
  3. From: pjl@cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Debugging output
  5. Message-ID: <Bx93Mr.42r@cs.uiuc.edu>
  6. Sender: news@cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <spuler.720931050@coral> <Bx9369.3zL@cs.uiuc.edu>
  9. Date: Thu, 5 Nov 1992 16:11:14 GMT
  10. Lines: 61
  11.  
  12. In <Bx9369.3zL@cs.uiuc.edu> pjl@cs.uiuc.edu (Paul Lucas) writes:
  13.  
  14. >In <spuler.720931050@coral> spuler@coral.cs.jcu.edu.au (David Spuler) writes:
  15.  
  16. >>I was wondering whether anyone has any suggestions as to how to use the neat
  17. >>operator << to produce debugging output in a way that it can be removed
  18. >>easily from production code.  The obvious method is:
  19.  
  20. >>#ifdef DEBUG
  21. >>   cerr << .....
  22. >>#endif
  23.  
  24. >*****>    This has nothing to do with <<.
  25.  
  26. >>but I'd like to avoid the #ifdef -#endif lines.
  27.  
  28. >*****>    Why?  In a "final" version, you don't want debugging code in the
  29. >    object file.
  30.  
  31. >>I've been trying to declare my own "dbg" streams by inheriting it
  32. >>from the standard "ostream" class and redefining the << operators.
  33.  
  34. >    [stream that has flag whether to print elided]
  35.  
  36. >*****>    This is overkill; the same thing can be achieved without
  37. >    inventing another class:
  38.  
  39. >    #ifdef DEBUG
  40. >    #    define    CDEBUG    if ( debug ) cerr
  41. >    #else
  42. >    #    define    CDEBUG    //
  43. >    #endif
  44.  
  45. ****>    That only works if you have a C++-ignorant preprocessor, i.e., so
  46.     it won't strip the // comment.  This is one instance, among others,
  47.     why I would like to keep cpp //-ignorant; you can do all sorts of
  48.     hokey stuff that way.
  49.  
  50. >    // ...
  51.  
  52. >    CDEBUG << "here\n";
  53.  
  54. >    This allows the flexibility of having debugging "togglable"
  55. >    during development, presumeably by a command-line option, but
  56. >    can be compiled-out in the final version.
  57.  
  58. >>Is there a preprocessor macro trick to remove the dbg << statements? (doubtful)
  59.  
  60. >*****>    See above.
  61.  
  62. >>Is there a better method?  (e.g. making dbg a reference to an ostream?)
  63.  
  64. >*****>    Unnecessary; see above.
  65. >-- 
  66. >    - Paul J. Lucas                University of Illinois    
  67. >      AT&T Bell Laboratories        at Urbana-Champaign
  68. >      Naperville, IL            pjl@cs.uiuc.edu
  69. -- 
  70.     - Paul J. Lucas                University of Illinois    
  71.       AT&T Bell Laboratories        at Urbana-Champaign
  72.       Naperville, IL            pjl@cs.uiuc.edu
  73.