"array" vs. "&array" ?

Gary L. Randolph randolph at ektools.UUCP
Wed Jan 10 02:39:53 AEST 1990


In article <21621 at mimsy.umd.edu> chris at mimsy.umd.edu (Chris Torek) writes:
>In article <2368 at ektools.UUCP> randolph at ektools.UUCP (Gary L. Randolph) writes:
>>3.) ANSI extended the language definition to allow taking the 
>>    address of an array name, so an ANSI conformant compiler will
>>    now (correctly) yield pointer to array of T, or pointer to
>>    pointer to T.
>
>There is no `or' about it!  The result is a pointer to an array, NOT
>a pointer-to-pointer.  The two types are completely different.
>
>POINTERS AND ARRAYS ARE NOT NOW AND NEVER HAVE BEEN EQUIVALENT IN C.

True, but array *names* may certainly be treated as constant pointers.
Chris, I agree with what you say.  I have to admit, however, that the
sentence in question is taken verbatim from Harbison and Steele, pg 273,
section 11.6.4.

>
>There are a few special cases under which an object of type `array
>N of T' is converted to a value of type `pointer to T', and under which
>a declaration of type `array N of T' is converted to a declaration of
>type `pointer to T'.  This does not make the types equivalent.  They
>are not interchangeable.

Well, again I agree but then I am confused when I read, in K&R2, page 
200 A7.1: 

If the type of an expression or subexpression is "array of T," for
some type T, then the value of the expression is a pointer to the
first object in the array, and the type of the expression is altered
to "pointer to T".

They do not say that the above is true only for a few special cases.

Based on experience, I agree with Chris, but then I am confused when
reading the above in two texts that I rarely question.

Is the quote from Harbison and Steele wrong?

Am I wrong in the inference from K&R that:

float arrf[3] = {1.2,2.3,3.4};
arrf;            /*evaluates to pointer to float according to K&R*/
&arrf;           /*evaluates to pointer to pointer to float (my inference)*/

Now I'm aware that if we look at a two dimensional array that if
int arr[2][3];	/*for example*/
then it is quite different to say

&arr evaluates to pointer to array of int
as opposed to
&arr evaluates to pointer to pointer to int

since, in the first case, arr++ would increment sizeof(arr) and in the
second case, arr++ would increment sizeof(pointer), which is not right.

So how does page 200 of K&R apply here? Chris?

Gary



More information about the Comp.lang.c mailing list