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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ukma!darwin.sura.net!spool.mu.edu!umn.edu!The-Star.honeywell.com!saifr00.cfsat.honeywell.com!murali
  3. From: murali@saifr00.cfsat.honeywell.com (R. Muralidhar)
  4. Subject: Re: Debugging output
  5. In-Reply-To: pjl@cs.uiuc.edu's message of Thu, 5 Nov 1992 16:01:20 GMT
  6. Message-ID: <1992Nov5.185929.15279@saifr00.cfsat.honeywell.com>
  7. Organization: Honeywell Air Transport Systems Division
  8. References: <spuler.720931050@coral> <Bx9369.3zL@cs.uiuc.edu>
  9. Date: Thu, 5 Nov 92 18:59:29 GMT
  10. Lines: 55
  11.  
  12.  
  13. In <Bx9369.3zL@cs.uiuc.edu> pjl@cs.uiuc.edu (Paul Lucas) writes:
  14.  
  15. >In <spuler.720931050@coral> spuler@coral.cs.jcu.edu.au (David Spuler) writes:
  16.  
  17. >>I was wondering whether anyone has any suggestions as to how to use the neat
  18. >>operator << to produce debugging output in a way that it can be removed
  19. >>easily from production code.  The obvious method is:
  20.  
  21. >>#ifdef DEBUG
  22. >>   cerr << .....
  23. >>#endif
  24.  
  25. >>but I'd like to avoid the #ifdef -#endif lines.
  26.  
  27. >*****>    Why?  In a "final" version, you don't want debugging code in the
  28. >    object file.
  29.  
  30. I, too, have felt a similar need like David Spuler. For one, those #ifdef -
  31. #endif lines interfere with neatly indented code, are unsightly, and make
  32. the code less readable. (I don't discount their usefulness, don't get me
  33. wrong.)
  34.  
  35. >>I've been trying to declare my own "dbg" streams by inheriting it
  36. >>from the standard "ostream" class and redefining the << operators.
  37.  
  38. >    [stream that has flag whether to print elided]
  39.  
  40. >*****>    This is overkill; the same thing can be achieved without
  41. >    inventing another class:
  42.  
  43. >    #ifdef DEBUG
  44. >    #    define    CDEBUG    if ( debug ) cerr
  45. >    #else
  46. >    #    define    CDEBUG    //
  47. >    #endif
  48.  
  49. >    CDEBUG << "here\n";
  50.  
  51. This method will work only if all the information to be 'output' appears in
  52. one source line. What if I had to do (for readability purposes):
  53.  
  54.         CDEBUG << "here is senetence one.\n"
  55.                << "here is sentence two.\n";
  56.  
  57. The technique Paul Lucas suggests wouldn't work, but David's would.
  58.  
  59. Muralidhar Rajappa                    murali@saifr00@cfsat.honeywell.com
  60. Honeywell Commercial Flight Systems Group
  61. Phoenix, AZ 
  62. -- 
  63.                  _
  64.   /|/), , ;_ _  // .
  65. (/  /(_<_/ '(_(_X_<_
  66. murali@saifr00.cfsat.honeywell.com
  67.