Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utfyzx!sq!msb From: msb@sq.UUCP Newsgroups: comp.lang.c Subject: Re: standardizing integral type sizes Message-ID: <1987Apr15.144714.1020@sq.uucp> Date: Wed, 15-Apr-87 14:47:14 EST Article-I.D.: sq.1987Apr15.144714.1020 Posted: Wed Apr 15 14:47:14 1987 Date-Received: Thu, 16-Apr-87 02:39:15 EST References: <101@umich.UUCP> <791@xanth.UUCP> <1987Apr9.155110.28398@sq.uucp> <3162@jade.BERKELEY.EDU> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto Lines: 59 Checksum: 31401 Mike (My watch has windows) (!) Meyer (mwm@eris.BERKELEY.EDU) writes: > In article <1987Apr9.155110.28398@sq.uucp> msb@sq.UUCP (Mark Brader) writes: > >... The Draft Standard ... In effect ... guarantees ... > > > > char <= short <= int <= long > > char >= 8 bits, short >= 16 bits, int >= 16 bits, long >= 32 bits > > > >... with the further presumption, which has been part of C for a long > >time, that int operations are at least as efficient as other types. > > Unfortunately, these are only specified by implication (so far as I > can tell). If someone can provide a paragraph number ... Well, I did say "in effect". I guess you want the actual wording. Section 3.1.2.5 reads in part... # There are four types of signed integers, called signed char, short int, # int, and long int. ... # # A signed char occupies the same amount of storage as a "plain" char. # A "plain" int has the natural size suggested by the architecture of the # execution environment. ... The set of values of each signed integral # type is a subset of the values of the next type in the list above. This covers the first set of inequalities and the efficient-ints rule. The actual minimum sizes are implied by the values of SCHAR_MAX, SHRT_MAX, INT_MAX, and LONG_MAX, and the corresponding _MIN values, tabulated in Section 2.2.4.2. (Notice, incidentally, that the values are chosen in such a way that sign-magnitude or 1's complement arithmetic is okay within the word lengths mentioned; thus the smallest known-to-be-a-valid-int value is -32767 and not -32768.) > ... consider a > hypothetical Queer Machine for C (QM/C), which has 18 bit words ... > obvious implementation has int = short = 18 bits, and long = 36 bits. > Now, suppose I need 16 bits of magnitude on a signed value. Right, you have to declare it long for portability even though int would work on such a machine. I think I alluded to this in my own posting. But the thing is, this is a RARE CASE. If you have variables that you KNOW will need 17 bits of sign and magnitude but not as many as 19, AND you have enough of them or they are frequently enough used that efficiency on QM/C's is a problem, THEN by all means do tricks with ifdefs and typedefs. For normal cases, the guidelines I suggested before will work. > It would be nice if I could declare things so that the program > would break at _compile_ time [if you need variables >32 bits]. Try: #if (1UL << 35 == 0) sorry, machine must have at least 36-bit longs #endif (I'm not positive whether the U is necessary -- the Draft Standard doesn't mention what << does in case of overflow when the left operand is signed, and I don't want to think about it.) Mark Brader