[Zlib-devel] crc32 big/little endian
Mark Adler
madler at alumni.caltech.edu
Thu Apr 22 03:19:40 EDT 2010
On Apr 21, 2010, at 11:53 PM, Vincent Torri wrote:
> C ANSI (C89) specifies:
>
> sizeof(char) = 1
>
> sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
>
> and no change with signed or unsigned
>
> that's all.
No, that's not all. Minimum sizes are specified in C89. See below: "Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown". Also K&R 2nd edition (the ANSI C edition) says basically the same thing: "longs are at least 32 bits".
I can't find my K&R 1st edition to see what it says about that.
In any case the constraints are bits(char) <= bits(short) <= bits(int) <= bits(long), 8 <= bits(char), 16 <= bits(short), and 32 <= bits(long). zlib makes only those assumptions about char, short, int, and long (and their unsigned counterparts).
Mark
2.2.4.2 Numerical limits
A conforming implementation shall document all the limits specified
in this section, which shall be specified in the headers <limits.h>
and <float.h> .
"Sizes of integral types <limits.h>"
The values given below shall be replaced by constant expressions
suitable for use in #if preprocessing directives. Their
implementation-defined values shall be equal or greater in magnitude
(absolute value) to those shown, with the same sign.
* maximum 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
* maximum value for an object of type unsigned int
UINT_MAX 65535
* 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
More information about the Zlib-devel
mailing list