This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Varargs macros subtly broken
- To: Neil Booth <NeilB at earthling dot net>
- Subject: Re: Varargs macros subtly broken
- From: Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>
- Date: Wed, 27 Sep 2000 01:41:03 +0200
- Cc: Zack Weinberg <zackw at Stanford dot EDU>, gcc at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- References: <E13dHl8-0005rl-00@kings-cross.london.uk.eu.org> <20000924225710.A12825@pcep-jamie.cern.ch> <20000924171436.F28755@wolery.stanford.edu> <20000925184254.A14482@pcep-jamie.cern.ch> <20000925224320.J6182@wolery.stanford.edu> <20000926125627.B17752@pcep-jamie.cern.ch> <20000926232108.A15334@daikokuya.demon.co.uk>
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