This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Problem with macro params containing commas


On Fri, 2003-08-15 at 02:11, Jean-Eric Cuendet wrote:
> Hi,
> 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?
> Thanks
> -jec

I use:

#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,
Fn_Pair_CLASS_ID );

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:

#undef X
#define X(a) a

which is obtained by expanding the definition
of X manually.

Hope this helps!




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