[comp.arch] C pointers in longs

andrew@frip.wv.tek.com (Andrew Klossner) (04/12/89)

[]

	"The (d)pANS has nuked the notion that you can stuff pointers
	into objects of any particular integral type ..."

But an int must still accommodate the result of subtracting two
pointers into the same array, so, if you're going to permit arrays of
more than 2GB, you'll need wider ints.

  -=- Andrew Klossner   (uunet!tektronix!orca!frip!andrew)      [UUCP]
                        (andrew%frip.wv.tek.com@relay.cs.net)   [ARPA]

henry@utzoo.uucp (Henry Spencer) (04/14/89)

In article <11274@tekecs.GWD.TEK.COM> andrew@frip.wv.tek.com (Andrew Klossner) writes:
>But an int must still accommodate the result of subtracting two
>pointers into the same array...

Nope, sorry, a "ptrdiff_t" must accommodate that result.  There is
absolutely no guarantee that ptrdiff_t == int; all you know is that
it's some signed integer type and it's defined in one of the standard
headers.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

guy@auspex.auspex.com (Guy Harris) (04/15/89)

>But an int must still accommodate the result of subtracting two
>pointers into the same array,

No, the (d)pANS has also nuked the idea that the difference between two
pointers must fit into an "int".  It must fit into *some* integral type,
and the implementation must supply an include file <stddef.h> that,
among other things, must define a "typedef" named "ptrdiff_t" that is
the integral type in question.

>so, if you're going to permit arrays of more than 2GB, you'll need
>wider ints.

No, you need wider "long"s at most.  It's not clear from a quick reading
of the standard whether an implementation that supports "long long int",
say, and that typedefs "ptrdiff_t" as "long long int", would be
conforming.  A conforming implementation implementation can, as I read
it, support "long long int", since I don't see any way for that
extension to cause a strictly conforming program to become invalid.  In
any case, it's quite possible that an implementation with 64-bit
pointers may well have 64-bit "long"s, and thus could have 32-bit "int"s.

blarson@skat.usc.edu (Bob Larson) (04/16/89)

In article <11274@tekecs.GWD.TEK.COM> andrew@frip.wv.tek.com (Andrew Klossner) writes:

>But an int must still accommodate the result of subtracting two
	^^^ a signed integral type
>pointers into the same array, so, if you're going to permit arrays of
>more than 2GB, you'll need wider ints.
	   ^^^ 2G objects	  ^^^ signed integral type

Just becuse arrays of one byte objects are limited to 2GB does not mean
other arrays are limited to 2GB.

-- 
Bob Larson	Arpa: Blarson@Ecla.Usc.Edu	blarson@skat.usc.edu
Uucp: {sdcrdcf,cit-vax}!oberon!skat!blarson
Prime mailing list:	info-prime-request%ais1@ecla.usc.edu
			oberon!ais1!info-prime-request