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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.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: <Bx9ouD.82M@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> <1992Nov5.185929.15279@saifr00.cfsat.honeywell.com>
  9. Distribution: usa
  10. Date: Thu, 5 Nov 1992 23:49:25 GMT
  11. Lines: 61
  12.  
  13. In <1992Nov5.185929.15279@saifr00.cfsat.honeywell.com> murali@saifr00.cfsat.honeywell.com (R. Muralidhar) writes:
  14.  
  15. >In <Bx9369.3zL@cs.uiuc.edu> pjl@cs.uiuc.edu (Paul Lucas) writes:
  16.  
  17. >>In <spuler.720931050@coral> spuler@coral.cs.jcu.edu.au (David Spuler) writes:
  18.  
  19. >>>I was wondering whether anyone has any suggestions as to how to use the neat
  20. >>>operator << to produce debugging output in a way that it can be removed
  21. >>>easily from production code.  The obvious method is:
  22.  
  23. >>>#ifdef DEBUG
  24. >>>   cerr << .....
  25. >>>#endif
  26.  
  27. >>>but I'd like to avoid the #ifdef -#endif lines.
  28.  
  29. >>*****>    Why?  In a "final" version, you don't want debugging code in the
  30. >>    object file.
  31.  
  32. >I, too, have felt a similar need like David Spuler. For one, those #ifdef -
  33. >#endif lines interfere with neatly indented code, are unsightly, and make
  34. >the code less readable. (I don't discount their usefulness, don't get me
  35. >wrong.)
  36.  
  37. *****>    You can indent preprocessor directives too, you know.
  38.  
  39. >>>I've been trying to declare my own "dbg" streams by inheriting it
  40. >>>from the standard "ostream" class and redefining the << operators.
  41.  
  42. >>    [stream that has flag whether to print elided]
  43.  
  44. >>*****>    This is overkill; the same thing can be achieved without
  45. >>    inventing another class:
  46.  
  47. >>    #ifdef DEBUG
  48. >>    #    define    CDEBUG    if ( debug ) cerr
  49. >>    #else
  50. >>    #    define    CDEBUG    //
  51. >>    #endif
  52.  
  53. >>    CDEBUG << "here\n";
  54.  
  55. >This method will work only if all the information to be 'output' appears in
  56. >one source line. What if I had to do (for readability purposes):
  57.  
  58. >        CDEBUG << "here is senetence one.\n"
  59. >               << "here is sentence two.\n";
  60.  
  61. >The technique Paul Lucas suggests wouldn't work, but David's would.
  62.  
  63. *****>    Mine would work:
  64.  
  65.     CDEBUG << "here is senetence one.\n";
  66.     CDEBUG << "here is sentence two.\n";
  67.  
  68.     you just have to use it, like all things, properly; David's class
  69.     is, as I've said, overkill.
  70. -- 
  71.     - Paul J. Lucas                University of Illinois    
  72.       AT&T Bell Laboratories        at Urbana-Champaign
  73.       Naperville, IL            pjl@cs.uiuc.edu
  74.