Contiguous Arrays

Herman Rubin cik at l.cc.purdue.edu
Fri Feb 24 01:09:49 AEST 1989


In article <1831 at valhalla.ee.rochester.edu>, badri at valhalla.ee.rochester.edu (Badri Lokanathan) writes:
> > In article <1828 at valhalla.ee.rochester.edu>, I said
| < <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;
> 
> In article <1989Feb22.171441.7957 at utzoo.uucp>,
> henry at utzoo.uucp (Henry Spencer) writes:
> > 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.

The desired effect should be obtainable by a struct.  But what is really 
wanted here is the Fortran EQUIVALENCE statement to guarantee that the 
right thing is done.  Another way that this can be done is to use some
assembler code to force the arrays to line up.

Why do language gurus work so hard to keep us from doing the obvious?
-- 
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907
Phone: (317)494-6054
hrubin at l.cc.purdue.edu (Internet, bitnet, UUCP)



More information about the Comp.lang.c mailing list