preprocessor/9764: Varargs macro extension incorrectly expands if the varargs argument is the macro itself

Ryan Mallon rpm31@student.canterbury.ac.nz
Thu Feb 20 00:01:00 GMT 2003



neil@gcc.gnu.org wrote:

>Synopsis: Varargs macro extension incorrectly expands if the varargs argument is the macro itself
>
>State-Changed-From-To: open->closed
>State-Changed-By: neil
>State-Changed-When: Wed Feb 19 23:48:50 2003
>State-Changed-Why:
>    3.1 and later give the following, which is correct.  I've not checked 3.0, but I expect it's similar.
>    
>    $ cat /tmp/bar.c
>    #define func(a, varargs...) _func(a, ##b)
>
Opps, I dont know how I missed that. The above line is incorrect, it 
should read:

#define func(a, varargs...) _func(a, ##varargs)

Which is valid and allows the following uses:

func(a);
func(a, b);
func(a, b, c);

Which preprocess correctly to:

_func(a);
_func(a, b);
_func(a, b, c);

The problems occurs when the macro name itself is used in the varargs 
part: e.g

func(a, func(b, c));

Incorrectly expands to:

_func(a, func(b, c));

Without the token paste opperator in the defintion it works as expected, 
but then I cannot have varargs=0. Im working with a large amount of 
existing code, so I cannot alter the actual calls on the macro definition.

Sorry for the inconvience,
Ryan Mallon




More information about the Gcc-bugs mailing list