[comp.std.c] Range of Enum Constants

kdb@chinet.chi.il.us (Karl Botts) (11/04/90)

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.
*/

kaiser@ananke.stgt.sub.org (Andreas Kaiser) (11/05/90)

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@ananke.stgt.sub.org
:: Andreas Kaiser :: fido: 2:509/5.2512 & 2:507/18.7206
::::::::::::::::::::