C'mon, guys!
Stanley Friesen
friesen at psivax.UUCP
Sat Jun 14 05:06:07 AEST 1986
In article <769 at aimmi.UUCP> gilbert at aimmi.UUCP (Gilbert Cockton) writes:
>
>Despite reading three years of discussion on and off on the pointer-array
>equivalance topic, as a casual user of C, I've never been able to come
>up with a clear view on when pointers and arrays are equivalent.
>I'm sure much of my confusion has actually been caused by reading the
>news.
>
>Any volunteers for a simple set of statements that get the message
>across? There must be many C compiler experts out there.
>
OK, I'll try. First statement
* A two-dimensional array is an array of one-dimensional arrays, and
multi-dimensioanl arrays are produced by repeating this composition
process.
>All I can start with is a straw man, as I'm no expert.
>
>* given an array of dimensions a x b x c .. x n,
> the array name is a pointer to array[0][0][0]..[0]
>
* Close, the array name is a *constant* pointer to the first
b x c x .. x n dimensional *subarray*, i.e. to array[0].
>* the only time this is any real use if when passing arrays by reference
> as `array' is easier and safer to write than
>
> &(array[0][0][0]..[0])
>
> as you don't need to bear the array dimensions in mind.
* I would say its real use is to allow writing algorithms which
may be applied to any one of several similar arrays by using
a pointer instead of an array and initializing the pointer to
the first element of the array. (especially since 'array' is
equivalent to '&(array[0])' rather than the longer form you
suggest)
To summarize, given the declaration:
TYPE array[a][b][c]...[n];
the following two usages are equivalent:
array &array[0]
--
Sarima (Stanley Friesen)
UUCP: {ttidca|ihnp4|sdcrdcf|quad1|nrcvax|bellcore|logico}!psivax!friesen
ARPA: ??
More information about the Comp.lang.c
mailing list