Varargs macros subtly broken
Jamie Lokier
egcs@tantalophile.demon.co.uk
Tue Sep 26 16:41:00 GMT 2000
Neil Booth wrote:
> "F, b"
>
> where F is a function-like macro (very common in your *cough* macros).
> F cannot be expanded here because no '(' follows it. However, this
> argument can be substituted within the expansion list of a macro, say
> SomeMacro, causing it to be *split up* as so:
>
> #define SomeMacro(...) A(__VA_ARGS__)
> #define A(a, b) a(b)
>
> SomeMacro(F, b)
>
> And here, in the expansion of A, F now has the required '(' after it,
> and so undergoes expansion itself. What a shame.
>
> Needless to say, I don't think I can fix this within the current code.
*boggle* you mean this is broken even without varargs? Ouch!
Lots of my programs use function-like macros in this way, for the most
basic things like hash tables and sorting functions.
E.g. "FAST_MERGE_SORT (a, b, STRCMP_LIKE_COMPARISON_MACRO)".
I'll have to see if they still compile. Oh, they do. What am I missing
from the above explanation?
-- Jamie
More information about the Gcc-bugs
mailing list