Re: Q: void* vs. unsigned long (fwd)

John Cochran (kernel@fiawol.org)
Tue, 16 Feb 1999 23:50:54 -0500 (EST)


François Désarménien wrote:
>
> John Cochran wrote:
>
[snip...]
> > The 1st bullet indicates that rank is independant of representation and if
> > you look at the definitions within <limits.h> (5.2.4.2.1) you'll see that
> > signed char is at least 8 bits long
> > short int is at least 16 bits long
> > int is at least 16 bits long
> > long is at least 32 bits long
> > long long is at least 64 bits long
> >
>
> That's not exactly the definitions I've learnt:
>
> It should be assumed that:
>
> char *is* 8 bits
> short int *is* 16 bits
> int is the size of int nativly handled by your CPU: can be anything
> long *is* 32 bits
> long long *is* 64 bits
>
>
> >
> > There is no prohibition against all of the integer types being the same length
> > as long as the minimum requirements are meet.
> >
> > John Cochran
> >
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.rutgers.edu
> > Please read the FAQ at http://www.tux.org/lkml/
>
> Tell me if I made a mistake
Quoting from 5.2.4.2.1 Sizes of Integer Types <limits.h>

The values given below shall be replaced by constant expressions suitable
for use in #if preprocessing directives. Moreover, except for CHAR_BIT
and MB_LEN_MAX, the following shall be replaced by expressions that have
the same type as would an expression that is an object of the corresponding
type converted according to the integer promotions. Their implementation-
defined values shall be equal or greater in magnitude (absolute value) to
those shown, with the same sign.

The key phrase is that the "implementation-defined values shall be equal or
greater in magnitude (absolute value) to those shown." The section then goes
on to define the minumum acceptable values for the following (plus some)

CHAR_BIT 8
SCHAR_MIN -127
SCHAR_MAX +127
UCHAR_MAX 255

The above imply that a character has at least 8 bits (but can be more).

Then
SHRT_MIN -32767
SHRT_MAX +32767
USHRT_MAX 65535
This implies at least 16 bits for short integers

Then
INT_MIN -32767
INT_MAX +32767
UINT_MAX 65535
This implies at least 16 bits for integers

Then
LONG_MIN -2147483647
LONG_MAX +2147483647
ULONG_MAX 4294967295
This implies at least 32 bits for long integers

Finally
LLONG_MIN -9223372036854775807
LLONG_MAX +9223372036854775807
ULLONG_MAX 18446744073709551615
And this implies at least 64 bits for long long integers

One thing to note about the above minimum limits. They allow for signed numbers
to be in either ones complement or twos complement without any problems. What
seems to be common practice is that "real" machines have int equal in size to
long int and small machines have int equal in size to short int. The only
constant that you can rely on is:
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)

John Cochran

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/