Variable length arg lists for macros
Glenn Fowler[eww]
gsf at ulysses.homer.nj.att.com
Fri Sep 2 02:13:35 AEST 1988
In article <438 at ucsvc.unimelb.edu.au>, u5565522 at ucsvc.unimelb.edu.au (David Clunie) writes:
> ... Wouldn't it be nice to be able to do something like ...
> #ifdef TRACE
> #define tracef(s,...) printf(s,...)
> #else
> #define tracef(s,...) /* nothing */
> #endif
> ... Probably a bit late for the ANSI standard ...
too late, but here is the description of macro `...' args for
a local preprocessor extension:
If the last formal argument is followed by the `...'
token then it is replaced by the expanded value
of all remaining actual arguments and intervening `,'
tokens from the macro call. If there is only one formal
argument then the macro may be called with no actual
arguments, otherwise there must be at least one actual
argument for the last formal argument.
this would change the tracef() macro definition to
#define tracef(s,...) printf(s)
the `,' before the `...' is optional to satisfy all tastes
--
Glenn Fowler AT&T Bell Laboratories, Murray Hill
{ihnp4,allegra}!ulysses!gsf (201)-582-2195
More information about the Comp.std.c
mailing list