Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!think!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpsal2!hpcupt1!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.lang.c Subject: Re: Address of Array Message-ID: <2550034@hpisod2.HP.COM> Date: Mon, 30-Nov-87 14:13:11 EST Article-I.D.: hpisod2.2550034 Posted: Mon Nov 30 14:13:11 1987 Date-Received: Fri, 4-Dec-87 07:24:35 EST References: <126@citcom.UUCP> Organization: Hewlett Packard, Cupertino Lines: 51 > It recently occurred to me that there is no syntax to take the > address of an array, although an expression of that type can be > derived from an array of arrays, and a variable of that type > can be declared. The obvious syntax, &a, is incorrect because > you can only & an lvalue. > > [Neophytes, please don't tell the world the name of an array denotes > its address. It denotes the address of the first element, which > does not mean the same thing if you add an integer to it.] I screamed in horror when I read in K&R of this design botch. This is the fundamental reason you can now take any type (including a structure containing an array!!) and assign to it, pass it to and return it from functions, EXCEPT an array type. However, I propose the syntax "a[]" to refer to an lvalue which is the entire array a, and "&(a[])" (sorry, that's the precedence) to signify the address of the entire array a. In order to declare a formal parameter of an array type, one would have to supply the dimension in the brackets, since otherwise the size would be unknown: int (bubblesort(array, n))[MAX] int array[MAX], n; { int i, done, tmp, newarray[MAX]; newarray[] = array[]; /* copy the value of array to newarray */ /* gratuitous, yes, but this is an example */ do { done = 1; for (i = 0; i < n-1; i++) if (newarray[i] > newarray[i+1]) { tmp = newarray[i]; newarray[i] = newarray[i+1]; newarray[i+1] = tmp; done = 0; } } while (!done); return newarray[]; /* return the whole array */ } Dave Decot hpda!decot