Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!nike!ucbcad!ucbvax!sdcsvax!sdcrdcf!psivax!friesen From: friesen@psivax.UUCP (Stanley Friesen) Newsgroups: net.lang.c Subject: Re: C'mon, guys! Message-ID: <1263@psivax.UUCP> Date: Fri, 13-Jun-86 15:06:07 EDT Article-I.D.: psivax.1263 Posted: Fri Jun 13 15:06:07 1986 Date-Received: Tue, 17-Jun-86 20:21:11 EDT References: <200@pyuxv.UUCP> <1181@ncoast.UUCP> <350@dg_rtp.UUCP> Reply-To: friesen@psivax.UUCP (Stanley Friesen) Organization: Pacesetter Systems Inc., Sylmar, CA Lines: 53 In article <769@aimmi.UUCP> gilbert@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: ??