Re: Q: void* vs. unsigned long

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


On Tue, Feb 16, 1999 at 07:12:43PM -0800, david parsons wrote:
> In article <linux.kernel.36C900C8.EB3C534F@quark.vpplus.com>,
> Brian Gerst <bgerst@quark.vpplus.com> wrote:
> >H. Peter Anvin wrote:
> >> Actually, it will. sizeof(unsigned long) == sizeof(void *) == 8 on
> >> 64-bit architectures.
> >
> >I thought it was int that changed with the word size of the
> >architecture, not long. Most C books I've seen said long is always 32
> >bits regardless of the word size.

That's due to the original BSD networking code, that believed 'all the world's
a vax' (which has now been replaced by 'all the world's an x86'). I believe
that has been cleaned up.

> They're wrong. The only constraint on the size of long (and I may
> be making this up) is that sizeof(short) <= sizeof(int) <= sizeof(long)
> (presumably the proprietary-but-about-to-be-standard long long will
> have the constraint of sizeof(long) <= sizeof(long long), but here I
> AM making things up.)

No, the ISO standard mandates that char be at least 8 bits, short and int be at
least 16 bits, and long be at least 32 bits. Additionally each of the types
bit size must be a multiple of the char bit size (ie, outlawing 7 or 8 bit
chars on PDP-10 systems, which were used in some cases). Additionally,
positive integers must be represented internally as binary, but one's
complement and sign magnitude are allowed for signed integer representations
(for those of you who slept through your computer architecture classes, two's
complement is the normal representation these days, but some of the computers
first designed in the 60's used one's complement and signed magnitude).

Tieing in another thread, there is no guarantee in the current standard that
there be an integer large enough to hold a pointer. The PR1ME computers, and
other word oriented machines typically had char * pointers larger than a long.

BTW, I've written a C compiler for a machine that had different pointer formats
for char/void pointers and for other pointers. Great fun when dealing with
typical user code :-(

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