Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!ittatc!dcdwest!sdcsvax!sdchem!tps From: tps@sdchem.UUCP (Tom Stockfisch) Newsgroups: net.lang.c Subject: Re: Address of array Message-ID: <150@sdchema.sdchem.UUCP> Date: Thu, 20-Mar-86 18:10:50 EST Article-I.D.: sdchema.150 Posted: Thu Mar 20 18:10:50 1986 Date-Received: Sat, 22-Mar-86 23:39:23 EST References: <750@abic.UUCP> <2293@utcsri.UUCP> <313@hadron.UUCP> Reply-To: tps@sdchema.UUCP (Tom Stockfisch) Organization: Chemistry Dept, UC San Diego Lines: 40 [] >>>I have noticed that different compilers treat the & operator differently >>>when it is applied to arrays. In particular, the UNIX compiler I have >>>been using warns against it. K&R explicitly deny its legality... >>I agree that it is really a design flaw in the language, to make >>it illegal to form a pointer to an array. & should work on any >>'object'... Joe Yao replies >... >I don't really see what the problem is that people are moaning >about. If you want a pointer to the array, the array name itself >coerces to a pointer containing the memory location at the beginning >of the array. There is no such thing as a pointer to the whole >array: that is a Pasqualische or Fortranian notion. Pointers, in >C, only point to atomic or aggregate (structure/union) objects. I >whole-heartedly agree that for some uses it is rather nice to use >such things. That is why (excuse me while I put on my flak jacket >and asbestos suit) C is not the only language in the world worth >using... C *can* refer to whole arrays. If you really want to take the address of an array rather than just mentioning the array try struct ary { int a[SIZE]; } arr1, arr2; ... &arr1; f(arr1); arr1 = arr2; In this case 'arr1' by itself is not a pointer-constant but represents the whole array (really structure) and '&arr1' refers to a pointer to the whole array. 'arr1.a' is the more familiar pointer-constant pointing to the first element of the array, 'f(arr1)' passes the whole array to the function f(), and 'arr1 = arr2' assigns the whole array. SO WHO NEEDS PASCAL? --Tom Stockfisch, UCSD Chemistry