This is the mail archive of the gcc-help@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: CPP (preprocessor) quandry


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


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