From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tim Hollebeek To: law@cygnus.com Cc: jbuck@Synopsys.COM, gavin@cygnus.com, cgw@alum.mit.edu, egcs@egcs.cygnus.com Subject: Re: [PATCH] Fix for short-enums comparison bug Date: Sun, 28 Feb 1999 22:53:00 -0000 Message-ID: <199902112216.RAA27319@wagner.Princeton.EDU> References: <6271.918762821@hurl.cygnus.com> X-SW-Source: 1999-02n/msg00404.html Message-ID: <19990228225300.Sui36xW3moUcGzQZvtDVh07L0mEhunK3FD3Hnuu-CYA@z> 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."