Variable length arg lists for macros
Mark Jones
jones at ingr.UUCP
Fri Sep 9 02:28:38 AEST 1988
In article <3604 at phoenix.Princeton.EDU>, haahr at phoenix.Princeton.EDU (Paul Gluckauf Haahr) writes:
> > How do people feel about the idea of preprocessor macros with variable
> > length argument lists ?
> >
> > However this can not be done with macro calls. 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
> >
> > At present, this CANNOT BE DONE, without nesting parentheses (clumsy) or
> > using a call to an empty function (inefficient, unless you have inline
> > integration in an optimizing compiler).
If you want a trace function, try this one
#ifdef TRACE
#define TR(x) x
#else
#define TR(x)
#endif
Now, you can just say
.
.
.
TR(printf("entering buggy function"));
.
.
.
and all is well!
Bought from Dr Dobbs Journal, Only good thing to come out of that
magazine in months.(Did BYTE buy them out?) <-- Rhetorical question
Mark Jones
More information about the Comp.std.c
mailing list