CPP (preprocessor) quandry
Eljay Love-Jensen
eljay@adobe.com
Fri Nov 22 10:32:00 GMT 2002
Hi Buddy,
Thanks for the idea!
This "two-part macro" trick will work:
#define $MkEnum(name$) \
struct name$ {\
typedef enum {
#define $EndEnum(name$) \
} Type;\
Type m;\
name$(Type in) : m(in) { }\
operator Type () const { return m; }\
}
In use:
$MkEnum(Marx)
Groucho, Chico, Harpo, Gummo, Zeppo, Karl = 86
$EndEnum(Marx);
Voila! Slightly awkward, but acceptable. It could all be put on one line,
but I'm not sure if that'd be better or worse.
Note: C++ only, no C.
Thanks,
--Eljay
More information about the Gcc-help
mailing list