Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!nbires!hao!hplabs!hp-sdd!ncr-sd!ncrcae!ncsu!uvacs!edison!steinmetz!davidsen From: davidsen@steinmetz.UUCP Newsgroups: net.lang.c Subject: Re: Pointers and Arrays Message-ID: <839@steinmetz.UUCP> Date: Thu, 17-Jul-86 15:35:10 EDT Article-I.D.: steinmet.839 Posted: Thu Jul 17 15:35:10 1986 Date-Received: Sat, 19-Jul-86 02:48:31 EDT References: <1242@ncoast.UUCP> <418@dg_rtp.UUCP> <1267@ncoast.UUCP> <2201@umcp-cs.UUCP> <2206@umcp-cs.UUCP> Reply-To: davidsen@kbsvax.UUCP (Davidsen) Organization: GE CRD, Schenectady, NY Lines: 64 Keywords: address of arrays After thinking about the discussions about using the address operator on an array by name, I come to the reluctant conclusiont that it SHOULD be allowed in the new ANSI standard. I have read an understood the arguments against it, I have spent hours teaching the language and convincing students that they should not do it, but now I have to reluctantly say that there are some fairly good reasons why it should be allowed. Reason 1: "codification of existing practice" If three ports of SysV, 2 of 4.2BSD and three of the largest selling C compiler for PCDOS represent current practice, then it is legal. I admit that a few compiler BITCHED about it, but they compiled it. Reason 2: "modularity and information hiding" If I am writing a modular program in which I have the typedefs in an include file used by the programmers writing the modules, there is no way to allow them to take the address of an item which is defined by typedef unless they know that the item is (or isn't) an array. Example: typedef int PARTA[10]; typedef struct { int x,y; float t[40]; } PARTB; in a module... PARTA source, dest, *whead, work[2]; PARTB *head, workb; If PARTA is an array, I must say: whead = &dest[0]; while if it's not, I say: whead = &dest; This means that the beauty of having the content of types changable at some time is no longer present, and every programmer who works with them, even is s/he never uses the contents (passes addresses, etc, like FILES) must know the type. Reason 3: "common sense" After five years of teaching C, I have to agree with my students that it makes no sense to forbid this construct. To take the address of something use the address operator. I have seen this mistake made by students from major universities, and graduates of courses taught by high priced consultants, so it's not just my students. Moreover, there is already a major peculiarity in the was array names are handled, as compared to the way pointers work. This is in the operation of the sizeof operator, which gives the size of a pointer or sizeof an entire array. Conclusion: I don't find this very desirable, I just think that it makes more sense to allow it that not allow it. Hopefully the next language will do away with arrays, and eliminate the whole problem :> -- -bill davidsen ihnp4!seismo!rochester!steinmetz!--\ \ unirot ------------->---> crdos1!davidsen chinet ------/ sixhub ---------------------/ (davidsen@ge-crd.ARPA) "Stupidity, like virtue, is its own reward"