Re: Q: void* vs. unsigned long

Michael Meissner (meissner@cygnus.com)
Wed, 17 Feb 1999 08:50:06 -0500


On Wed, Feb 17, 1999 at 12:27:01AM -0500, Jon 'tex' Boone wrote:
>
> Oliver Xymoron <oxymoron@waste.org> writes:
> > But what we need here is "an integral type which can represent all
> > possible pointer values".
>
> How about "ptrdiff_t"?
>
> According to K&R[2e], pg 103:
>
> "The header <stddef.h> defines a type ptrdiff_t that is large enough
> to hold the signed difference of two pointer values."
>
> So, the unsigned version of whatever type ptrdiff_t is should be large
> enough to hold all possible pointer values, no?

Nope. In C, the difference between two pointers is only defined IFF both
pointers point into the same array (counting the requirement that you can form
a pointer to the element 1 byte beyond the end of the array, but not derefernce
said pointer as being in the same array). Thus if you have a limit on the size
of objects, ptrdiff_t can be smaller than the size of pointers. In fact, in
early x86's, some of the memory models used by the compilers had 32 bit
pointers, but ptrdiff_t was 16 bits, since the object size was limited to be
65K-1 or less.

-- 
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	617-354-5416 (office),	617-354-7161 (fax)

- 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/