Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!oliveb!ios!qubix!sun!gnu From: gnu@sun.uucp (John Gilmore) Newsgroups: net.lang.c Subject: Re: thoughts on &array Message-ID: <1736@sun.uucp> Date: Wed, 10-Oct-84 04:26:02 EDT Article-I.D.: sun.1736 Posted: Wed Oct 10 04:26:02 1984 Date-Received: Mon, 15-Oct-84 01:46:36 EDT References: <22197810.8e4@apollo.uucp> <981@bbncca.ARPA> <524@wjh12.UUCP> <986@bbncca.ARPA> Organization: Sun Microsystems, Inc. Lines: 47 It seems like people (maybe me?) are still confused between pointers and arrays. It has always seemed a botch that &array didn't work -- I remember when I first learned C, I just concluded that it was a broken language because &foo sometimes worked, sometimes failed, and sometimes was ignored, depending on the type of foo. Please check my understanding: A POINTER IS DIFFERENT FROM AN ARRAY. If you say char c1[10], *cp1; then cp1 = c1; works, but if you say char c2[10][5], **cp2; cp2 = c2; it does not work; you have to say char c2[10][5], *(cp3[5]); (Those who can recall C precedence may be able to remove parens above.) In the above, c1 is array of 10 char cp1 pointer to char c2 array of 10 array of 5 char cp2 pointer to pointer to char cp3 pointer to array of 5 char (The difference between a pointer an an array is: dereferencing an "array of N" leaves the address alone but changes the type to "N", while dereferencing a "pointer to N" actually gets a new address out of storage and types that address "N". Saying &c seems to create an array, not a pointer, since *&c doesn't get any value out of storage.) This has served as a rule of thumb for me for the last few years, can a real language designer or compiler hacker tell me if I'm right? It sounded to me like Steve Dyer was proposing that &c1 be c1 array of 10 char &c1 array of 1 array of 10 char just like c char &c array of 1 char It sounds good to me.