Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tekig4.UUCP
Path: utzoo!linus!decvax!tektronix!tekig5!tekig4!rosalia
From: rosalia@tekig4.UUCP (Mark Galassi)
Newsgroups: net.lang.c
Subject: C arrays and pointers
Message-ID: <138@tekig4.UUCP>
Date: Tue, 18-Jun-85 12:22:55 EDT
Article-I.D.: tekig4.138
Posted: Tue Jun 18 12:22:55 1985
Date-Received: Mon, 12-Aug-85 06:15:48 EDT
Reply-To: rosalia@reed.UUCP (Mark Galassi)
Distribution: net
Organization: Tektronix, Beaverton OR
Lines: 22


In article <459@rtech.UUCP> jas@rtech.UUCP (Jim Shankland) writes:
>> array==pointer ... is only true when "array" is being passed
>> or received as a parameter.

>...  "a[b]" is completely, syntactically, semantically,
>and rigorously IDENTICAL to "*(a+b)" (except, again, in an actual declaration).
>Of course, for the above to make sense, one of the operands must be a
>pointer to something, and the other an integral type; but it doesn't matter
>which is which.  It follows that "a[b]" is equivalent to "b[a]" -- a
>notion that most people will not accept without a little head-scratching.
>Jim Shankland

    I don't agree with you: *(a+b) is incorrect, and will not
pass lint's checking. Whay you want is *a + b, and the compiler will scale
b so that if a points to a 16-bit quantity, you will get *(a + 2b) and
so on. I also would like to see an example of your a[b] and b[a]: indexing
an array by pointers is strange, because the pointer b in a[b] would
have a value like 10 or 54 or something that makes sense in your array.
But then taking b[], you might access very weird machine locations.
					Mark Galassi
				...!tektronix!reed!rosalia