This is the mail archive of the
mailing list for the GCC project.
Re: Problem with macro params containing commas
- From: skaller <skaller at ozemail dot com dot au>
- To: Jean-Eric Cuendet <jec at rptec dot ch>
- Cc: gcc at gcc dot gnu dot org
- Date: 15 Aug 2003 19:50:28 +1000
- Subject: Re: Problem with macro params containing commas
- References: <email@example.com>
- Reply-to: skaller at ozemail dot com dot au
On Fri, 2003-08-15 at 02:11, Jean-Eric Cuendet wrote:
> I'd like to pass params that contains commas to a macro.
> But the macro processor think that the passed param is 2 parts (separated by the
> inner macro). It's normal, but not what I want...
> Is there a way to do it differently?
#define comma ,
... offsetof(X<A comma B>,x) ...
to solve this problem. I can get away with that solution
because I am generating the code .. I know when I'm passing
a single parameter to a macro, and so I can scan the string
and replace every ',' character with ' comma '.
#define MACRO_PARAM_1 <class First,class Second>
#define MACRO_PARAM_2 Fn_Pair<First,Second>
FN_DEFINE_TEMPLATE_CLASS_METHODS( MACRO_PARAM_1, MACRO_PARAM_2, Fn_Kind,
That doesn't work.
gcc says that FN_DEFINE_TEMPLATE_CLASS_METHODS requires 4 parameters ans
that 6 are passed!
The likely explanation is: after the initial expansion,
the text is rescanned, invoking a macro which is
passed the argument of the first macro .. which has now
been expanded to two arguments .. causing the error above.
There is a solution to this problem and many like it
which satisfy the property that macros called in
the definition of another macro are invariant
(that is, you don't use an argument to name a macro
to be called). For this class of problem
you can simply expand the inner macro calls manually.
Here is a (trivial) example:
#define X(a) Y(a)
#define Y(a) a
#define two x,y
.. Y(a) .. // fine ....
.. X(a) .. // WOOPS wrong number of argument
the fix is:
#define X(a) a
which is obtained by expanding the definition
of X manually.
Hope this helps!