sizeof (integral types)

Guy Harris guy at auspex.auspex.com
Wed Apr 19 05:00:55 AEST 1989


>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.)

Oh, yes, it is.  Try reading 2.2.4.2 "Numerical limits" as well, in the
December 7, 1988 draft (although it may well be in your older draft as
well):


	   A conforming implementation shall document all the limits
	specified in this section...

	Sizes of integral types <limits.h>

	   ...Their implementation-defined values shall be equal or
	greater in magnitude (absolute value) to those shown, with the
	same sign.

	   + minimum value for an object of type "signed char"

	     SCHAR_MIN				-127

	   + maximum value for an object of type "signed char"

	     SCHAR_MAX				+127

(8 bits per "char", minimum, on a binary machine - "-127", rather than
"-127", since the machine may be one's complement; for "unsigned char",
the "minimum maximum" value is 255, so again it's 8 bits, minimum, on
binary machines)

	   + minimum value for an object of type "short int"

	     SHRT_MIN				-32767

	   + maximum value for an object of type "short int"

	     SHRT_MAX				+32767

(16 bits per "short int", minimum, on a binary machine; USHRT_MAX is
65535, so it's again 16 bits on binary machines)

It says similar things for "int" (+/-32767 for "int", 65535 for
"unsigned int", so 16 bits, again, on binary machines) and "long int"
(+/-2147483647 for "long int", 4294967295 for "unsigned long int", so
it's 32 bits on binary machines).



More information about the Comp.lang.c mailing list