This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
CPP (preprocessor) quandry
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 22 Nov 2002 11:17:16 -0600
- Subject: CPP (preprocessor) quandry
- References: <006201c27f9d$c23a9f50$fd01a8c0@rhizome.org><m3d6psn3b0.fsf@scooby.brisbane.redhat.com>
Here's a simplified example of my quandry:
#define MkFoo(y) typedef y Foo
Users were happy with this solution, doing things like...
MkFoo(unsigned char);
...or...
MkFoo(signed long int);
...as they needed.
But then one day, a programmer needed this. But the following is No Good...
MkFoo(enum {a,b,c});
...since the preprocessor thinks the comma belongs to it.
So the usual way of embedding commas as a macro parm is by another set of
parens:
MkFoo((enum {a,b,c}));
However, that expands to...
typedef (enum {a,b,c}) Foo;
...which is still No Good.
What is the preprocessor trick to strip out the extra parens?
Or is there an inverse of stringification (passing the parm in as a quoted
string and then stripping the quotes would be acceptable, if possible)?
Don't suggest templates. Not appropriate for this code base.
Thanks,
--Eljay
(I hate macros.)