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.


[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Re: [PATCH] Fix for short-enums comparison bug



Jeffrey A Law writes ...
> 
> 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?

I seriously doubt it, since arguments to integer operators undergo
integral promotion.  The rules are different for C++, but I believe
the answer is no, since none of the standard integral types is allowed
to have only 2 bits.

---------------------------------------------------------------------------
Tim Hollebeek                           | "Everything above is a true
email: tim@wfn-shop.princeton.edu       |  statement, for sufficiently
URL: http://wfn-shop.princeton.edu/~tim |  false values of true."