home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15824 < prev    next >
Encoding:
Text File  |  1992-11-05  |  1.7 KB  |  62 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: <Bx9369.3zL@cs.uiuc.edu>
  6. Sender: news@cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <spuler.720931050@coral>
  9. Date: Thu, 5 Nov 1992 16:01:20 GMT
  10. Lines: 50
  11.  
  12. In <spuler.720931050@coral> spuler@coral.cs.jcu.edu.au (David Spuler) writes:
  13.  
  14. >I was wondering whether anyone has any suggestions as to how to use the neat
  15. >operator << to produce debugging output in a way that it can be removed
  16. >easily from production code.  The obvious method is:
  17.  
  18. >#ifdef DEBUG
  19. >   cerr << .....
  20. >#endif
  21.  
  22. *****>    This has nothing to do with <<.
  23.  
  24. >but I'd like to avoid the #ifdef -#endif lines.
  25.  
  26. *****>    Why?  In a "final" version, you don't want debugging code in the
  27.     object file.
  28.  
  29. >I've been trying to declare my own "dbg" streams by inheriting it
  30. >from the standard "ostream" class and redefining the << operators.
  31.  
  32.     [stream that has flag whether to print elided]
  33.  
  34. *****>    This is overkill; the same thing can be achieved without
  35.     inventing another class:
  36.  
  37.     #ifdef DEBUG
  38.     #    define    CDEBUG    if ( debug ) cerr
  39.     #else
  40.     #    define    CDEBUG    //
  41.     #endif
  42.  
  43.     // ...
  44.  
  45.     CDEBUG << "here\n";
  46.  
  47.     This allows the flexibility of having debugging "togglable"
  48.     during development, presumeably by a command-line option, but
  49.     can be compiled-out in the final version.
  50.  
  51. >Is there a preprocessor macro trick to remove the dbg << statements? (doubtful)
  52.  
  53. *****>    See above.
  54.  
  55. >Is there a better method?  (e.g. making dbg a reference to an ostream?)
  56.  
  57. *****>    Unnecessary; see above.
  58. -- 
  59.     - Paul J. Lucas                University of Illinois    
  60.       AT&T Bell Laboratories        at Urbana-Champaign
  61.       Naperville, IL            pjl@cs.uiuc.edu
  62.