"array" vs. "&array" ?

Karl Heuer karl at haddock.ima.isc.com
Wed Jan 17 12:25:26 AEST 1990


In article <5260 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>In article <15638 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>>In article <5248 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>>>Usually when you ask for the pointer to an array you get a
>>>pointer to the first element of the array.
>>
>>No, you get a pointer to the entire array (in ANSI C) or an error (in K&R
>>C), except in those pre-ANSI compilers that chose, as an extension, to make
>>the misinterpretation you describe (usually accompanied by a warning).
>
>"those...that chose" happens to describe all the compilers I can find
>(three different pre-ansi, one ansi-I-think (it's gcc with the ansi
>switch turned on...)).

As I said, in ANSI C you get a pointer to the entire array.  You claim that
gcc gives you a pointer to the first element instead.  I don't think you've
tested it in a way that would distinguish those two results.  A pointer to an
entire array and a pointer to the first element, after being converted to a
common type, will compare equal.

Exercise: design a program that will print "ANSI" if the compiler defines &a
as I described, or "non-ANSI" if it simply ignores the &.  Compile it with gcc
and at least one pre-ANSI compiler, and tell us what you find.

Karl W. Z. Heuer (karl at haddock.isc.com or ima!haddock!karl), The Walking Lint
(I'll skip the rest of the article, since I don't think we're talking on the
same wavelength yet.)



More information about the Comp.lang.c mailing list