Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Contiguous Arrays Message-ID: <1989Feb22.171441.7957@utzoo.uucp> Organization: U of Toronto Zoology References: <2508@ssc-vax.UUCP> <8943@alice.UUCP> <1828@valhalla.ee.rochester.edu> Date: Wed, 22 Feb 89 17:14:41 GMT In article <1828@valhalla.ee.rochester.edu> badri@valhalla.ee.rochester.edu (Badri Lokanathan) writes: >For instance, if the array was to be x[101] to x[110] instead of >x[0] to x[9], what is the easiest way to do it? >For automatic arrays one could do >int space[10], *x; >x = &space[0] - 101; No one couldn't, not if one wants to be portable. There is absolutely no guarantee that x[101] will be the same as space[0], and in fact there is no guarantee that the computation of x won't trap and give you a core dump. On a sufficiently odd segmented machine it might. Even K&R1 warns you that pointer arithmetic won't necessarily do what you think unless you keep it within an array. -- The Earth is our mother; | Henry Spencer at U of Toronto Zoology our nine months are up. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu