home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ascent!eb
- From: eb@ascent.com (Ed Barton)
- Subject: Re: Debugging output
- In-reply-to: ort@netcom.com's message of 9 Nov 92 11:20:51 GMT
- Message-ID: <EB.92Nov10081925@ascent.ascent.com>
- Date: 10 Nov 92 08:19:25
- References: <spuler.720931050@coral> <1992Nov9.112051.21350@netcom.com>
- Organization: Ascent Technology, Inc., Cambridge Massachusetts
- Lines: 36
-
-
- In article <1992Nov9.112051.21350@netcom.com> ort@netcom.com (David Oertel) 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.
-
- I didn't see the truly obvious answer to this post. That is to
- put the #ifdef,#endif around the body of an inline function.
-
- Someone please correct me if I'm wrong, but I thought the arguments to
- an inline function still had to be evaluated, even if they aren't used
- in the body. So if you write
-
- void debug(ostream& expr) {
- #ifdef DEBUG
- if (debug_flag) expr << endl;
- #endif
- }
-
- debug(cout << "foo: " << foo);
-
- wouldn't the compiler still have to arrange to do the output anyway as
- part of argument evaluation, even when DEBUG is not defined? I
- thought it's not supposed to matter to the result whether a function
- is inline or not.
-
- Or maybe I misunderstood the suggestion?
-
-
-