home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!pilchuck!fnx!sgihbtn!dkarr
- From: dkarr@sierra.com (David Karr)
- Subject: Re: Debugging output
- Message-ID: <1992Nov6.184126.8975@sierra.com>
- Sender: news@sierra.com
- Nntp-Posting-Host: dopey
- Organization: Sierra Geophysics, Kirkland WA
- X-Newsreader: Tin 1.1 PL4
- References: <spuler.720931050@coral>
- Date: Fri, 6 Nov 1992 18:41:26 GMT
- Lines: 35
-
- spuler@coral.cs.jcu.edu.au (David Spuler) writes:
- :
- : [Sorry if this is a re-post. The first one seemed to get lost.]
- :
- : 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
- :
- : but I'd like to avoid the #ifdef -#endif lines.
- :
- : I've been trying to declare my own "dbg" streams by inheriting it
- : from the standard "ostream" class and redefining the << operators.
-
- I don't know of an elegant way to remove the generated code, but you can
- implement a derivative of streambuf that will allow you to suppress the
- debug output at run time (from the environment).
-
- In the streambuf derivative, override the "overflow" method such that
- before sending the data out, call a ptr to function which sends the data to
- be sent out to a "filter" function (the ptr to function is set in the
- streambuf constructor). If your environment indicates that you don't want
- the debugging output, then your function will return False from the
- "filter" function, which will cause "overflow" to not use the characters.
-
- I got a hint on how to do this from the book "AT&T C++ Language System",
- distributed by CenterLine Software (with ObjectCenter).
- --
- David M. Karr
- Sierra Geophysics, Inc.
- ARPA: dkarr@sierra.com, UUNET: uunet!sgihbtn!dkarr
- Phone: (206) 822-5200 (x343)
-