p[1] vs. *(p+1)

Wayne Throop throopw at sheol.UUCP
Mon Sep 10 06:54:35 AEST 1990


>> throopw at sheol.UUCP
>>I think it is misleading to say that "adding one to p 'really' adds
>>sizeof(*p) to p". [...]  I say it "really" adds 1, and the result [...]
>>points at an element [...] offset exactly 1

> From: hunter at Oswego.EDU (Eric Hunter)
> It doesn't "really" add 1; it increments the pointer variable to the next
> available address.

Which, I still claim, is "really" adding one.  My argument was against
assuming that the integer representation of pointers was to indicate a
byte offset.  This is not true for some current machines, and is at
best a misleading way of thinking about the situation.

"The next available address" may well NOT be "sizeof element" architectural
units away from the address one starts with.  Or it may well be exactly
one unit away, for element type of short, or int, or even double.

I think it is a bad idea to explain abstract things in terms of a concrete
implementation in other than examples.
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org



More information about the Comp.lang.c mailing list