Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!munnari.oz.au!metro!seagoon.newcastle.edu.au!jupiter.newcastle.edu.au!dgorton From: dgorton@jupiter.newcastle.edu.au (David Mark Gorton) Newsgroups: comp.lang.c++ Subject: #define Message-ID: Date: 29 May 91 23:52:08 GMT Sender: news@neddy.newcastle.edu.au Distribution: comp Organization: Uni of Newcastle, Australia Lines: 34 Is there a simple way to have #defines with a variable length parameter list? Example of Problem: ------------------- I wish to do something like the following in a "debug.h" file #define nl << "\n" #define endl << "\n" << flush (are these defined somewhere ?? - I have seen them in some manuals) #define DEBUG_PRINT(a) if (debug) cout << a endl #define DEBUG_PRINT2(a, b) if (debug) cout << a << b endl #define DEBUG_PRINT3(a, b, c) if (debug) cout << a << b << c endl #define DEBUG_PRINT4(a, b, c, d) if (debug) cout << a << b << c << d endl etc. with one (or perhaps two) #define(s) if possible. Can it be achieved with the # and ## preprocessor operators for example? I know about #ifdef so please dont write pages on the example used for simplicity above. I am also aware of variable length parameter lists, va_arg() etc - but wish to avoid them if a simpler solution is possible. Thanks in advance, Dave --------------------------------------------------------------------------- Dave Gorton. Department of Computer Science, University of Newcastle, Newcastle, 2308, Australia. .-_|\ Telephone : (049) 216 034 / \ \.--._/ Internet : dgorton@cs.newcastle.edu.au v ---------------------------------------------------------------------------