Possible bug in VAX 11/750 C compiler
Kevin Long
klong at datlog.UUCP
Thu Aug 15 02:20:45 AEST 1985
Our company is running system 5.2 on a VAX 11/750 and we have a problem with
our compiler in the area of compile time evaluation of constants.
The problem has appeared after using the system include file values.h to
define the value MAXSHORT, the maximum value a short can hold.
This is defined as follows.
#define BITSPERBYTE 8
#define BITS(type) (BITSPERBYTE * (int)sizeof(type))
#define HIBITS ((short)(1 << BITS(short) - 1))
#define MAXSHORT ((short)~HIBITS)
After cpp has finished with MAXSHORT it looks like
((short)~((short)(1 << (8 * (int)sizeof(short)) - 1)))
and the compiler treats this at compile time as -32769; (of some size).
If we now define
int a = 1;
Then neither of the following code works as expected
if ( (short) a < MAXSHORT) ....;
if ( a < (int) MAXSHORT) ....;
The problem is created by the compiler evaluating constants as longs, signed
unless explicitly told to do otherwise, so the problem goes away if short is
changed to unsigned short in the definitions of MAXSHORT and HIBITS above;
Is this a bug in the compiler or a bad definition in values.h ??
--
Klong
The views expressed above are not those of my employer but those of my pet Panda
UUCP: ...!mcvax!ukc!stc!datlog!klong
MAIL: Data Logic Ltd., 320, Ruislip Road East, Greenford, Middlesex, UK.
More information about the Comp.lang.c
mailing list