This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: underlying type for enums
On Wed, Dec 03, 2003 at 02:51:07AM +0000, Jamie Lokier wrote:
> If you were to say the type is an integer of the minimum number of
> bits required to represent all the enumerators, and set
> TYPE_MIN/MAX_VALUE according to that, will GCC assume that range for
> the purpose of optimisation?
In some places. Perhaps only the switch generator at present.
> In particular, if you do that can GCC generate a sequence of
> shifts/masks that modify bits outside the bitfield s.e in this example?
>
> typedef enum { RED, GREEN, YELLOW } E;
> struct { E e : 2; unsigned f : 1; } s;
> E e2;
> *(char *)&e2 = 4;
> // Can this modify s.f?
> s.e = (__typeof__(s.e)) e2;
I don't know. Certainly we wouldn't at present.
r~