This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Help with bit-field semantics in C and C++
Andreas Schwab <schwab@suse.de> writes:
| Michael Matz <matz@suse.de> writes:
|
| > In this case I think the C++ standard should be changed in a way to not
| > require a masking operation for each and every assignment from an integer
| > of which the range is unknown. Yes this masking happens only for such
| > casts, and not for every operation if the operands are enums already, but
| > it still will hurt performance in the real world.
|
| Do you think that assignments from non-enum to enum are frequent
| operations in C++? I don't think so. The explicit cast also suggests
| that the conversion may not be a nop.
Yup. Just like any other cast operation that may be
value-trasmutting.
If you really want to store an out-of-range value in an enum, use
reinterpret_cast<int&>(e) = 7;
That should take you to somewhere.
-- Gaby