This is the mail archive of the egcs@egcs.cygnus.com mailing list for the EGCS project. See the EGCS home page for more information.
> My quick read of the C++ standard made it appear as if assigning a value that
> was not a member of the enum resulted in undefined results.
Wrong. The ISO C++ standard defines what values must be assignable to the
enum, and it is a larger set of values than just the members. I don't
have the language in front of me, but the intent is to require the ability
to hold intermediate values and AND and OR of legal values. Thus code
like the following is standard-conformant:
enum flags {
flag_none = 0x0,
flag_a = 0x1,
flag_b = 0x2,
flag_c = 0x4,
flag_d = 0x8
};
...
flags foo = (flags)(flag_a | flag+b); // OK
flags bar = (flags) 12; // OK
flags xyz = (flags) 23; // not OK
the last one is not guaranteed to work because the compiler is allowed to
use a four-bit unsigned field and 23 will not fit.
> case where C++ and C differ?