Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site steinmetz.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!mcnc!ncsu!uvacs!edison!steinmetz!davidsen From: davidsen@steinmetz.UUCP (Davidsen) Newsgroups: net.lang.c Subject: Re: Address of array Message-ID: <685@steinmetz.UUCP> Date: Fri, 14-Mar-86 10:05:04 EST Article-I.D.: steinmet.685 Posted: Fri Mar 14 10:05:04 1986 Date-Received: Sun, 16-Mar-86 00:47:15 EST References: <750@abic.UUCP> <211@dg_rtp.UUCP> Reply-To: davidsen@kbsvax.UUCP (Davidsen) Organization: GE CRD, Schenectady, NY Lines: 49 Summary: In article <211@dg_rtp.UUCP> throopw@dg_rtp.UUCP (Wayne Throop) writes: >> 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. >> However, the operation seems to me to be perfectly >> reasonable when the desired result is a pointer to the array rather >> than a pointer to the first element of the array. > >I agree that C's treatment of array/function/struct addresses is >inconsistant, confusing, and limiting. In essence a small notational >convenience was traded for a large consistancy headache. I think the >tradeoff was wrong, but I'm not sure that your proposal would clarify >things. I believe that to support reasonable portable code C *must* allow the address operator on an array, even if it is not required. Consider: prog.c: #include "globals.h" /* project global symbols and types */ foo() { LOCAL m,n; process(&m); } globals.h: typedef long LOCAL[10]; ================ Since LOCAL is a typedef which is an array, the programmer would not be able to write code which would work with a legal typedef for LOCAL unless the & operator was allowed for an array. To require special code to handle arrays and scalars defeats the intent of information hiding, and requires global changes to the source is a typedef is changes, for instance, from an array to a structure. This was pointed out to me by someone on X3J11, but I can't remember who in order to give credit for this example. -- -bill davidsen seismo!rochester!steinmetz!--\ / \ ihnp4! unirot ------------->---> crdos1!davidsen \ / chinet! ---------------------/ (davidsen@ge-crd.ARPA) "It seemed like a good idea at the time..."