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]

Re: Varargs macros subtly broken


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

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