klong@datlog.UUCP ( Kevin Long ) (08/14/85)
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.
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (08/18/85)
> 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. > ... > Is this a bug in the compiler or a bad definition in values.h ?? This is the ICON bug for which I posted a fix to net.bugs.usg several months ago.