Variable arguments in macros

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Apr 18 23:41:46 AEST 1989


In article <89Apr17.163342edt.11027 at ephemeral.ai.toronto.edu> bradb at ai.toronto.edu (Brad Brown) writes:
>I've been trying to find a way to have macros with variable numbers of
>arguments in ANSI C, and I don't think it can be done.

Not as such.

There is a trick that is sometimes convenient (but not in this
particular case):

#define FOO(x) bar x
FOO((a,b,c))	/* expands to: bar (a,b,c) */

>What I'd like to do is have a header file with a macro similar to 
>	#define trace(s)  { fprintf( stderr, s ); }

What I do for this is to define a variable-argument function that
invokes vfprintf() to do the printing.



More information about the Comp.std.c mailing list