This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Compiling GCC with g++: a report
> This doesn't do what I want at all. The goal is to make the *symbolic
> enumeration constants* inaccessible to most code.
Oh.
enum {
THE_VAL_QUUX_ENUMS
} TheValQuux;
If not defined, you get one enum, THE_VAL_QUUX_ENUMS. The "authority"
can define it to a list of enums, so it gets expanded. Now, if we can
figure out a solution to the "enums are the smallest integral type
they fit in" problem, we'd be all set. This might work with a suitable
terminator on the real list:
enum {
THE_VAL_QUUX_ENUMS = 32767;
} TheValQuux;
The private header would have something like:
#define THE_VAL_QUUX_ENUMS \
TVQ_FOO1, \
TVQ_FOO2, \
TVQ_FOO3, \
TVQ_NUM_ENTRIES, \
TVQ_INT_MAX
If it's OK to have the enums in a header, provided you can't *use* them...
enum {
#ifdef TVQ_AUTHORITATIVE_ENUMS
TVQ_FOO1,
TVQ_FOO2,
TVQ_FOO3,
TVQ_NUM_ENTRIES,
#endif
TVQ_INT_SIZER = 32767;
} TheValQuux;
This won't stop a suitably enthusiastic programmer from getting to
them anyway, but that's always the case.
Or...
#ifndef TVG_ENUM
#define TVG_ENUM(X) DONT_USE_ME_TVG_##x
#endif
enum {
TVG_ENUM(FOO1),
TVG_ENUM(FOO2),
TVG_ENUM(FOO3),
} TheValQuux;
With the "authority" suitably defining TVG_ENUM.
Of course, these are all just hacks to hide the enumerations.