Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Contiguous Arrays Message-ID: <16080@mimsy.UUCP> Date: 22 Feb 89 23:48:22 GMT References: <2508@ssc-vax.UUCP> <8943@alice.UUCP> <1828@valhalla.ee.rochester.edu> <1831@valhalla.ee.rochester.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 22 In article <1831@valhalla.ee.rochester.edu> badri@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@mimsy.umd.edu Path: uunet!mimsy!chris