Contiguous Arrays
Chris Torek
chris at mimsy.UUCP
Thu Feb 23 09:48:22 AEST 1989
In article <1831 at valhalla.ee.rochester.edu> badri at valhalla.ee.rochester.edu
(Badri Lokanathan) writes:
>... But Henry's statement implies that on some architectures
>
>(x + i) - i != x + (i - i)
/* where x is a pointer */
This is correct: on some architectures, if `x' is one of the integral
types except the unsigned types, or if x is a pointer type, x + i may
cause an overflow trap, iff the address computed by x+i is not within
the object denoted by x. (That is: on some machines, there exists an
integer $i$ such that $x+i = \error$.)
The trick described is, however, portable whenever the `zero point' of
the derived array is contained within the array, because in that case
we know that 0 <= i <= N (where N is the number of elements in the array)
and the pANS guarantees that this address is computable (does not cause a
range error). (That is: $\forall i \elem [0,N], x+i$ is computable, and
$(x+i)-i = x$.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list