Article View: comp.std.c
Article #5306Re: Variable length arg lists for macros
From: Peter Rowell
Date: Thu, 01 Sep 1988 19:04
Date: Thu, 01 Sep 1988 19:04
25 lines
1458 bytes
1458 bytes
If the reason for variable arguments is to pass them to a routine
that takes varargs, the following horrible hack seems not only to
work but to be portable!
#define d_printf(level, stuff) ((level>=debug_level)? printf stuff :level=level)
Note: NO parentheses --> ^ ^
This is then invoked by:
d_printf(8, ("foo overflow: %d > %d", some_foo, max_foo));
^ <----- Note the parentheses -----------> ^
By placing parentheses around the args for printf, they become 1 arg
from the point of view of the macro expander. The reason for the ?: usage
is to allow this "if" anywhere a single expression could be without
screwing up things like:
if (cond) d_printf(x,("bummer")); else somehthingelse;
----------------------------------------------------------------------
Peter Rowell (You will need a bigger rock.)
Third Eye Software, Inc. (415) 321-0967
Menlo Park, CA 94025 ...!pyramid!thirdi!peter
Technical Details
Message-ID:
<429@thirdi.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!purdue!decwrl!hplabs!pyramid!thirdi!peterReferences:
<438@ucsvc.unimelb.edu.au> <1036@cbnews.ATT.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!purdue!decwrl!hplabs!pyramid!thirdi!peter From: peter@thirdi.UUCP (Peter Rowell) Newsgroups: comp.std.c,comp.lang.c Subject: Re: Variable length arg lists for macros Message-ID: <429@thirdi.UUCP> Date: 1 Sep 88 19:04:26 GMT References: <438@ucsvc.unimelb.edu.au> <1036@cbnews.ATT.COM> Reply-To: peter@thirdi.UUCP (Peter Rowell) Organization: Third Eye Software, Menlo Park, CA Lines: 25