Range of Enum Constants
Karl Botts
kdb at chinet.chi.il.us
Sun Nov 4 19:21:40 AEST 1990
I am sending this to Microsoft; I thought it might be relevent here, too:
/*
Dear Microsoft Online,
MSC 6.0 correctly compiles this:
*/
enum {
A = (int)0x8001,
};
/*
but rejects this:
*/
enum {
B = (int)0x8000,
};
/*
with:
enum.c
enum.c(16) : error C2141: value out of range for enum constant
This doesn't make any sense, since both are valid values for a
16-bit integer.
This may be related to something I noticed in <limits.h>:
#define SHRT_MIN (-32767) /* minimum (signed) short value */
#define SHRT_MAX 32767 /* maximum (signed) short value */
This is clearly wrong. I don't have a copy of the ANSI standard,
but I suppose it is possible that it requires that the the _MIN and _MAX
constants for a signed integral type have the same absolute value.
If so we'll have to live with it, but otherwise you have a bad header
file.
If you have compiled the compiler using your <limits.h> this is
probably the source of the enum problem, above. But I claim that
regardless of the ANSI standard, the enum problem is a bug.
*/
/*
You may wonder how I ran into this. Well, I have a set of EMS
access routines which generate error codes by clearing the al register
if an EMS function fails; the native EMS error codes are in ah, and one
of them is 0x80. I wanted to make a a set of enum constants for these
codes.
*/
More information about the Comp.std.c
mailing list