Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ico!ism780c!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Adding two pointers Message-ID: <13004@haddock.ima.isc.com> Date: 8 May 89 23:05:41 GMT References: <2765@buengc.BU.EDU> <563@lzaz.ATT.COM> <4093@ficc.uu.net> <17340@mimsy.UUCP> <4646@freja.diku.dk> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 21 In article <4646@freja.diku.dk> njk@freja.diku.dk (Niels J|rgen Kruse) writes: >The word "array" as used when saying that two pointers must point into the >same array in order to subtract them is a bit foggy to me. What about > struct { char c; double d; } x[10]; >Are (& x[3].d) and (& x[7].d) not pointing into x? Not in this sense. They point into (different) arrays of type `double [1]'. >Is (&x[3].d - &x[7].d) undefined? Yes (even after I fixed the typo). On some machines, there does not exist an integer k such that (&x[1].d == &x[0].d + k), so it would be meaningless to attempt to evaluate (&x[1].d - &x[0].d) to any integer. >What array is (char *)x pointing into? An array of type `char [sizeof(x)]' (or equivalently, `char [10*sizeof(S)]' where S is the struct type) whose existence is supposedly implied by the pANS statement that `objects are composed of bytes'. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint