Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!rutgers!gatech!mcnc!rti!xyzzy!tiktok!meissner From: meissner@tiktok.dg.com (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: sizeof (integral types) Message-ID: <5387@xyzzy.UUCP> Date: 25 Apr 89 22:24:42 GMT References: <10044@smoke.BRL.MIL> <7.UUL1.3#5109@pantor.UUCP> Sender: usenet@xyzzy.UUCP Reply-To: meissner@tiktok.UUCP (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 116 In article <7.UUL1.3#5109@pantor.UUCP> richard@pantor.UUCP (Richard Sargent) writes: | gwyn@smoke.BRL.MIL (Doug Gwyn) in Message-ID: <10044@smoke.BRL.MIL> writes: | > | > In article <12005@paris.ics.uci.edu> Doug Schmidt writes: | > >I realize the relation short <= int <= long holds, I'm just curious | > >whether there is any minimum that these basic types must meet (e.g., | > >short >= 16 bits, etc.). | > | > chars are at least 8 bits, | > shorts are at least 16 bits, | > longs are at least 32 bits. | | I quote from the ANSI C DRAFT dated January 11, 1988, Section 3.1.2.5: | | An object declared as type char is large enough to store any member | of the basic execution character set. ... | | There are four _signed integer types_, designated as signed char, | short int, int, and long int. ... | | ... A "plain" int object has the natural size SUGGESTED by the | architecture of the execution environment ( ... in the header ). | In the list of signed integer types above, the range of values of each | type is a subrange of the values of the next type in the list. | | Please note that this definition explicitly avoids any claims about the sizes | of the types except for the "<=" business in the first message. It most | definitely does NOT say anything about 8, 16, or 32 bits! In fact, the | definition permits implementations of 8 bit longs and others of 32 bit chars! | (Of course, no one in their right mind would try to sell such a product, | but it is not forbidden by the language definition.) And I quote from an eariler section (2.2.4.2) in the draft, dated December 7, 1988 -- it seems like it's nailed down to me. By the way, this section has been in the draft for at least two years. The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Moreoever, except for CHAR_BIT and MB_LEN_MAX, the following shall by replaced by expressions that have the same type as would an expression that is an object of the corresponding type converted according to the integral promotions. Their implemtation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign. * number of bits for smallest object that is not a bit-field (byte) CHAR_BIT 8 * minimum value for an object of type signed char SCHAR_MIN -127 * maximum value for an object of type signed char SCHAR_MAX +127 * maximum value for an object of type unsigned char UCHAR_MAX 255 * minimum value for an object of type char CHAR_MIN see below * maximum value for an object of type char CHAR_MAX see below * maximum number of bytes in a multibyte character, for any supported locale. MB_LEN_MAX 1 * minimum value for an object of type short int SHRT_MIN -32767 * maximum value for an object of type short int SHRT_MAX 32767 * maximum value for an object of type unsigned short int USHRT_MAX 65535 * minimum value for an object of type int INT_MIN -32767 * maximum value for an object of type int INT_MAX 32767 * minimum value for an object of type long int LONG_MIN -2147483647 * maximum value for an object of type long int LONG_MAX 2147483647 * maximum value for an object of type unsigned long int ULONG_MAX 4294967295 If the value of an object of type char is treated as a signed integer when used in an expression, the value of CHAR_MIN shall be the same as SCHAR_MIN and the value of CHAR_MAX shall be the same as SCHAR_MAX. Otherwise, the value of CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as UCHAR_MAX. [see 3.1.2.5] -- Michael Meissner, Data General. Uucp: ...!mcnc!rti!xyzzy!meissner If compiles were much Internet: meissner@dg-rtp.DG.COM faster, when would we Old Internet: meissner%dg-rtp.DG.COM@relay.cs.net have time for netnews?