home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
- From: pjl@cs.uiuc.edu (Paul Lucas)
- Subject: Re: Debugging output
- Message-ID: <Bx9369.3zL@cs.uiuc.edu>
- Sender: news@cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <spuler.720931050@coral>
- Date: Thu, 5 Nov 1992 16:01:20 GMT
- Lines: 50
-
- In <spuler.720931050@coral> spuler@coral.cs.jcu.edu.au (David Spuler) writes:
-
- >I was wondering whether anyone has any suggestions as to how to use the neat
- >operator << to produce debugging output in a way that it can be removed
- >easily from production code. The obvious method is:
-
- >#ifdef DEBUG
- > cerr << .....
- >#endif
-
- *****> This has nothing to do with <<.
-
- >but I'd like to avoid the #ifdef -#endif lines.
-
- *****> Why? In a "final" version, you don't want debugging code in the
- object file.
-
- >I've been trying to declare my own "dbg" streams by inheriting it
- >from the standard "ostream" class and redefining the << operators.
-
- [stream that has flag whether to print elided]
-
- *****> This is overkill; the same thing can be achieved without
- inventing another class:
-
- #ifdef DEBUG
- # define CDEBUG if ( debug ) cerr
- #else
- # define CDEBUG //
- #endif
-
- // ...
-
- CDEBUG << "here\n";
-
- This allows the flexibility of having debugging "togglable"
- during development, presumeably by a command-line option, but
- can be compiled-out in the final version.
-
- >Is there a preprocessor macro trick to remove the dbg << statements? (doubtful)
-
- *****> See above.
-
- >Is there a better method? (e.g. making dbg a reference to an ostream?)
-
- *****> Unnecessary; see above.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-