#: 3308 S3/Languages
06-May-90 15:16:59
Sb: #3305-C arrays
Fm: Bruce MacKenzie 71725,376
To: Mark Griffith 76070,41 (X)
Again, I'll have to come to Jeff's defense. I think that nearly everything
he's said has been right on the mark, but unfortunately he's been misconstrued.
First, lets forget about initialization and memory allocation. That's a side
issue and confuses things. Let's talk about pointers and their attributes.
Arrays ar implemented in C as pointers. A one dimension array, say char p[12],
is implemented as a pointer, p, which is a pointer to the simple data type,
char. p[1] is only another way of saying *(p+1), ie what's pointed to by p
after it has been incremented by 1.
Now a two dimension array, say p[2][12], again is implemented as a pointer, p,
which now is a pointer to the complex data type, 'array of 12 characters'.
Since the data type is itself an array, implicit in this definition are two
pointers, p[0] and p[1] (these are not true variables, stored in memory, but
are derived on the fly by incrementing p). These are pointers to the simple
data type, char, and point to the start of each 12 character array.
So in this manner multidimension array handling is built up by a recursive
application of the properties of pointers. Jeff was right on when he said that
multidimension arrays are really arrays of arrays.
|