This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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




neil at gcc dot gnu dot 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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]