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: <6707@otc.otca.oz>
- Date: 8 Nov 92 00:28:16 GMT
- References: <spuler.720931050@coral> <Bx9369.3zL@cs.uiuc.edu> <Bx93Mr.42r@cs.uiuc.edu> <6706@otc.otca.oz>
- Sender: news@otc.otca.oz
- Organization: Technology Development Group, OTC Australia
- Lines: 42
-
- In article <6706@otc.otca.oz>, grahamd@swdev.research.otca.oz.au (Graham Dumpleton) writes:
- > In article <Bx93Mr.42r@cs.uiuc.edu>, pjl@cs.uiuc.edu (Paul Lucas) writes:
- >
- > #ifdef DEBUG
- > #define CDEBUG if (!debug) ; else cerr
- > #else
- > #define CDEBUG if (1) ; else cerr
- > #endif
-
- One further point about this, in optimising away the body of the 'else' when
- DEBUG isn't defined, cfront does not even parse and type check the code which
- is eliminated. For example, cfront wouldn't complain about debugstream being
- undefined in the following when DEBUG isn't defined
-
- #ifdef DEBUG
- ofstream debugstream("debug");
- #endif
-
- #ifdef DEBUG
- #define CDEBUG if (!debug) ; else debugstream
- #else
- #define CDEBUG if (1) ; else debugstream
- #endif
-
- ...
-
- CDEBUG << "hello world" << endl;
-
- If this approach is used it may not be wise to rely on this to occur for all
- compilers though so you may be better off writing
-
- #ifdef DEBUG
- #define CDEBUG if (!debug) ; else debugstream
- #else
- #define CDEBUG if (1) ; else cerr
- #endif
-
- I would be interested to hear what other C++ compilers do in this situation,
- ie. do they actually check the code which is eliminated.
-
- --
- Graham Dumpleton (grahamd@swdev.research.otca.oz.au)
-