Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!uunet!cimshop!davidm From: cimshop!davidm@uunet.UU.NET (David S. Masterson) Newsgroups: comp.lang.c++ Subject: Re: #define Message-ID: Date: 30 May 91 17:40:24 GMT References: Sender: davidm@cimshop.UUCP Distribution: comp Organization: Consilium Inc., Mountain View, California Lines: 40 In-reply-to: dgorton@jupiter.newcastle.edu.au's message of 29 May 91 23:52:08 GMT >>>>> On 29 May 91 23:52:08 GMT, dgorton@jupiter.newcastle.edu.au (David Mark >>>>> Gorton) said: David> Example of Problem: David> ------------------- David> I wish to do something like the following in a "debug.h" file David> #define DEBUG_PRINT(a) if (debug) cout << a endl David> #define DEBUG_PRINT2(a, b) if (debug) cout << a << b endl David> #define DEBUG_PRINT3(a, b, c) if (debug) cout << a << b << c endl David> etc. How about: #define DEBUG_PRINT(a) if (debug) cout << a << endl // note ----^^ then use it as follows: DEBUG_PRINT(a); DEBUG_PRINT(a << b); DEBUG_PRINT("a = " << a); DEBUG_PRINT(a << b << c); // etc. David> I know about #ifdef so please dont write pages on the example used for David> simplicity above. I am also aware of variable length parameter lists, David> va_arg() etc - but wish to avoid them if a simpler solution is David> possible. If you're going to try to get fancy, then you'll probably want to build a function and use va_arg(). The above example has been more than sufficient for me, especially after hooking it up with the Tracer object defined in E&S (chapter 3, I think). -- ==================================================================== David Masterson Consilium, Inc. (415) 691-6311 640 Clyde Ct. uunet!cimshop!davidm Mtn. View, CA 94043 ==================================================================== "If someone thinks they know what I said, then I didn't say it!"