CPP (preprocessor) quandry

Eljay Love-Jensen eljay@adobe.com
Fri Nov 22 09:17:00 GMT 2002


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.)



More information about the Gcc-help mailing list