[Bug preprocessor/56825] Preprocessor does not expand macro correctly if it is an argument and argument of a macro contains ##

harald at gigawatt dot nl gcc-bugzilla@gcc.gnu.org
Wed Apr 3 17:31:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56825

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #3 from Harald van Dijk <harald at gigawatt dot nl> 2013-04-03 17:31:26 UTC ---
For the related
  #define foo(x, y) x ## y
both foo(f,oo(,)) and foo(,foo(,)) expand similarly to foo(,) and in that case,
that is the only valid expansion in standard C (C99, anyway). The macro
argument foo(,) is not expanded during argument substitution because it is an
operand of a ## operator. The macro argument is not expanded after argument
substitution because that happens in the context of another expansion of the
same foo macro.

> But IMHO this statement is relevant to the macro itself and should not apply to the argument of the macro

That is exactly what it is meant to apply to.

#define A 1
#define B 2
#define AB 3
#define C(a, b) a ## b
C(A, B)

must expand to 3. Neither A nor B is allowed to be expanded here before
concatenation takes place. AB must be expanded after that, as long as no other
expansion of AB is already taking place.

That said,
  , ## x
is a GNU extension that never concatenates (except for the rare case where x is
an empty macro argument), so the standard cannot and does not require it to
behave exactly the same way as the concatenation operator.



More information about the Gcc-bugs mailing list