Range of Enum Constants

Andreas Kaiser kaiser at ananke.stgt.sub.org
Tue Nov 6 02:59:01 AEST 1990


In your msg to All, dated <05 Nov 90 08:31>, it said:

 KB> enum { A = (int)0x8001, };
 KB>         but rejects this:
 KB> enum { B = (int)0x8000, };

 KB> enum.c(16) : error C2141: value out of range for enum constant

 KB>         This doesn't make any sense, since both are valid values for a
 KB>  16-bit integer.

0x8000 is NOT a valid integer. -0x8000 IS a valid integer.

 KB>         This may be related to something I noticed in <limits.h>:

 KB> #define SHRT_MIN      (-32767)
 KB> #define SHRT_MAX       32767

 KB>         This is clearly wrong.  I don't have a copy of the ANSI
 KB> standard, but I suppose it is possible that it requires that the the
 KB> _MIN and _MAX constants for a signed integral type have the same
 KB> absolute value.

BTW: Did you mean (-32768) ? The numbers in your include-file extract above HAVE the same absolute value.

I have not seen the mentioned restriction to symetrical limits in the MWC ANSI C book. It would enforce a one-s complement representation for integers. A funny idea today. 

                Andreas

 A funny idea today. 

                Andreas

--  
:::::::::::::::::::: uucp: kaiser at ananke.stgt.sub.org
:: Andreas Kaiser :: fido: 2:509/5.2512 & 2:507/18.7206
::::::::::::::::::::



More information about the Comp.std.c mailing list