Help with bit-field semantics in C and C++
Joe Buck
Joe.Buck@synopsys.COM
Tue Aug 24 17:43:00 GMT 2004
[ issues connected with limited range of C++ enums ]
On Tue, Aug 24, 2004 at 10:32:39AM -0600, Roger Sayle wrote:
> I'm happy with the explanations so far. The next question is, if
> the middle-end is supposed to treat loads, stores and comparisons
> of these types identically to the underlying integer type for the
> enumeration, is there a benefit for setting TYPE_PRECISION lower
> than GET_MODE_BITSIZE for C++'s enumerated types?
I think that the middle end should, at least by default, try to generate
the best code possible for conformant programs that use C++ enums. In
most cases, that probably means treating them as belonging to the
underlying integer type; the exception would be where the limited range
allows for, say, more efficient switch statements, or to determine that
some code is unreachable.
It's possible to have the compiler generate enum range-checking code, but
doing so would seem inconsistent with how we do everything else. It would
only make sense in the context of a bounds-checking compiler that would
also handle array bounds and the like.
More information about the Gcc
mailing list