This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
range of enums
- To: Jeffrey A Law <law at hurl dot cygnus dot com>
- Subject: range of enums
- From: Charles G Waldman <cgw at alum dot mit dot edu>
- Date: Sat, 13 Feb 1999 11:26:31 -0500 (EST)
- Cc: egcs at egcs dot cygnus dot com
Jeffrey Law wrote:
> typedef enum {A=0, B, C, D} T;
> main(){
> T x;
> for (x=A; x<=D; ++x)
> printf("%d ", (int)x);
> putchar('\n');
> }
>
> So the compiler could use a 2 bit unsigned field for x since the values for
> enum T are 0, 1, 2, 3. Other values will not fit and would be considered
> invalid. Thus removing the test x <= D is technically valid for C++. Right?
>
> That (of course) isn't binding for C.
Is it worth pointing out that in fact gcc/egcs does not use any such
bit fields for representing enums, so an argument based on the fact
that it *could* seems somewhat empty?
As long as we know that it's using standard char|int|long int
types to represent enums isn't it reasonable to have comparisons work
correctly based on this knowledge? If and when gcc/egcs gets modified
to use bitfields to represent enums (which seems a somewhat remote
possibility) a lot more work will be necessary to produce the
appropriate checks warnings when an enum is assigned to.