Bug in cpp macro varargs extension

Zack Weinberg zack@rabi.columbia.edu
Wed Mar 31 23:54:00 GMT 1999


On Tue, 2 Mar 1999 13:19:50 -0500 (EST), "Kaveh R. Ghazi" wrote:
>	Does anyone use gcc's macro varargs extension?  Is is
>considered usable?
>
>	I'm having several problems getting correct expansions.  I think
>it boils down to this test case:
>
> > #define error1(msg, args...) printf(msg, "foo", ## args)
> > #define error2(msg, args...) printf("foo", msg, ## args)
[...]

## args, where args is an empty rest argument, deletes the `preceding
sequence of nonwhitespace characters', not the preceding token.  You
want

#define error1(msg, args...) printf(msg, "foo" , ## args)

Yes this is ugly.  It's done this way since cpp doesn't know what the
"preceding token" is.  cpp.info says that "we" may consider changing
it to the preceding token in the future.  Presumably this would
involve a token-based macro expander.  I've been thinking about that
idly.  The benefits are not clear, besides making it easier to
implement C89 Amendment 1 digraphs.

cpplib behaves identically.

zw



More information about the Gcc-bugs mailing list