home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: pjl@cs.uiuc.edu (Paul Lucas)
- Subject: Re: Debugging output
- Message-ID: <Bx9ouD.82M@cs.uiuc.edu>
- Sender: news@cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <spuler.720931050@coral> <Bx9369.3zL@cs.uiuc.edu> <1992Nov5.185929.15279@saifr00.cfsat.honeywell.com>
- Distribution: usa
- Date: Thu, 5 Nov 1992 23:49:25 GMT
- Lines: 61
-
- In <1992Nov5.185929.15279@saifr00.cfsat.honeywell.com> murali@saifr00.cfsat.honeywell.com (R. Muralidhar) writes:
-
- >In <Bx9369.3zL@cs.uiuc.edu> pjl@cs.uiuc.edu (Paul Lucas) writes:
-
- >>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
-
- >>>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, too, have felt a similar need like David Spuler. For one, those #ifdef -
- >#endif lines interfere with neatly indented code, are unsightly, and make
- >the code less readable. (I don't discount their usefulness, don't get me
- >wrong.)
-
- *****> You can indent preprocessor directives too, you know.
-
- >>>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 method will work only if all the information to be 'output' appears in
- >one source line. What if I had to do (for readability purposes):
-
- > CDEBUG << "here is senetence one.\n"
- > << "here is sentence two.\n";
-
- >The technique Paul Lucas suggests wouldn't work, but David's would.
-
- *****> Mine would work:
-
- CDEBUG << "here is senetence one.\n";
- CDEBUG << "here is sentence two.\n";
-
- you just have to use it, like all things, properly; David's class
- is, as I've said, overkill.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-