Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!pilchuck!dataio!fnx!nazgul!bright From: bright@nazgul.UUCP (Walter Bright) Newsgroups: comp.lang.c Subject: 32 bit longs Message-ID: <231@nazgul.UUCP> Date: 19 Jan 91 07:39:32 GMT References: <14824@smoke.brl.mil> <1991Jan13.182655.17672@athena.mit.edu> <1291@mti.mti.com> Reply-To: bright@nazgul.UUCP (Walter Bright) Distribution: comp Organization: Zortech, Seattle Lines: 31 Many times I've seen code that says a type needs to be 32 bits wide when what is really meant is >=32 bits is needed. This is typical when one sees a typedef like: typedef long int32; This typedef implies that exactly 32 bits is required, rather than >=32. Note that on a PDP-10, longs are 36 bits! A more portable approach would be to have a typedef indicating what type you need, like: typedef long fileoffset_type; /* need at least 32 bits */ If you have a need for *exactly* 32 bits, you can do things like: x &= 0xFFFFFFFF; /* truncate result to 32 bits */ Any decent compiler will not generate any code for that if x is 32 bits wide (and isn't volatile!). Alternatively, you can do things like: if (sizeof(x) == 4) /* code here depends on 32 bits in x */ ... else /* Portability alert! */ assert(0); /* rewrite this algorithm! */ P.S. I prefer stuff like: #if sizeof(long) == 4 ... #else #error This algorithm needs to be ported #endif but ANSI C seems to have torpedoed that.