Contiguous Arrays
Henry Spencer
henry at utzoo.uucp
Thu Feb 23 03:14:41 AEST 1989
In article <1828 at valhalla.ee.rochester.edu> badri at 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 at zoo.toronto.edu
More information about the Comp.lang.c
mailing list