home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!doc.ic.ac.uk!agate!spool.mu.edu!darwin.sura.net!sgiblab!munnari.oz.au!mel.dit.csiro.au!mineng.dmpe.CSIRO.AU!dmssyd.syd.dms.CSIRO.AU!metro!otc!swdev!grahamd
- From: grahamd@swdev.research.otca.oz.au (Graham Dumpleton)
- Newsgroups: comp.lang.c++
- Subject: Re: Debugging output
- Message-ID: <6706@otc.otca.oz>
- Date: 8 Nov 92 00:00:32 GMT
- References: <spuler.720931050@coral> <Bx9369.3zL@cs.uiuc.edu> <Bx93Mr.42r@cs.uiuc.edu>
- Sender: news@otc.otca.oz
- Organization: Technology Development Group, OTC Australia
- Lines: 57
-
- In article <Bx93Mr.42r@cs.uiuc.edu>, pjl@cs.uiuc.edu (Paul Lucas) 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:
- >
- > >*****> This is overkill; the same thing can be achieved without
- > > inventing another class:
- >
- > > #ifdef DEBUG
- > > # define CDEBUG if ( debug ) cerr
- > > #else
- > > # define CDEBUG //
- > > #endif
- >
- > ****> That only works if you have a C++-ignorant preprocessor, i.e., so
- > it won't strip the // comment. This is one instance, among others,
- > why I would like to keep cpp //-ignorant; you can do all sorts of
- > hokey stuff that way.
- >
- > > // ...
- >
- > > 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.
-
- Noting that cfront, and I imagine any 'good' compiler, will optmise away the
- body of an 'if' statement if given a condition which can be evaluated at compile
- time, you can say.
-
- #ifdef DEBUG
- #define CDEBUG if (debug) cerr
- #else
- #define CDEBUG if (0) cerr
- #endif
-
- One problem with this though, which David Spuler pointed out to me when I told
- him about it, is that for safety you are best off writing
-
- #ifdef DEBUG
- #define CDEBUG if (!debug) ; else cerr
- #else
- #define CDEBUG if (1) ; else cerr
- #endif
-
- If you didn't and some one wrote
-
- if (...)
- CDEBUG << "here\n";
- else
- ...
-
- you would end up with the 'else' matching the 'if' within the CDEBUG macro
- which could give some unexpected results.
-
- --
- Graham Dumpleton (grahamd@swdev.research.otca.oz.au)
-