pointer question

barrett at hpcnob.UUCP barrett at hpcnob.UUCP
Tue Apr 10 03:57:00 AEST 1984


How is p = p + 4 not portable when p is a pointer?  From K & R p 188:

   The result of the + operator  is the sum of the  operands.  A pointer to
   an  object  in an array and a value of any  integral  type may be added.
   The latter is in all cases converted to an address offset by multiplying
   it by the length of the object to which the pointer  points.  The result
   is a pointer of the same type as the original  pointer, and which points
   to  another  object in the same  array,  appropriately  offset  from the
   original  object.  Thus if P is a pointer  to an object in an array, the
   expression P+1 is a pointer to the next object in the array.

   No further type combinations are allowed for pointers.

It would seem that this is non-portable  only if used as something other
than an index into the  original  storage  area of the  pointer.  Do you
have an example of another case?

Dave Barrett (hplabs!hp-dcd!barrett)



More information about the Comp.lang.c mailing list