Contiguous Arrays

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Feb 24 02:34:11 AEST 1989


In article <1146 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>The desired effect should be obtainable by a struct.

??

>But what is really wanted here is the Fortran EQUIVALENCE statement ...

Gag, choke.  Ask any competent computer/language architect what he
thinks about FORTRAN'S EQUIVALENCE statement.  It really constrains
implementations in generally undesirable ways.

>Another way that this can be done is to use some
>assembler code to force the arrays to line up.

The idea wasn't to get x[] and space[] to "line up" so much as it
was to introduce space[] as a kludge in an attempt to avoid allocating
space for the unreferenced part of x[].  This doesn't work because of
the impossibility of computing out-of-range addresses for space[] on
some (e.g. segmented) architectures.

>Why do language gurus work so hard to keep us from doing the obvious?

Most Algol-like languages, and even FORTRAN-77, allow the exact range
of valid subscripts to be specified for an array.  C is rather unusual
in maintaining a simple model of array, always starting at [0].  There
are tradeoffs here; C's model has much nicer abstract properties, but
in exchange if the programmer wants offsets he has to arrange to get
them himself.  Fortunately that is quite trivial to accomplish, due
to the power of the C preprocessor.  In fact we discussed how to do
that in this newsgroup not very many months ago.



More information about the Comp.lang.c mailing list