Address of array
Tom Stockfisch
tps at sdchem.UUCP
Fri Mar 21 09:10:50 AEST 1986
[]
>>>I have noticed that different compilers treat the & operator differently
>>>when it is applied to arrays. In particular, the UNIX compiler I have
>>>been using warns against it. K&R explicitly deny its legality...
>>I agree that it is really a design flaw in the language, to make
>>it illegal to form a pointer to an array. & should work on any
>>'object'...
Joe Yao replies
>...
>I don't really see what the problem is that people are moaning
>about. If you want a pointer to the array, the array name itself
>coerces to a pointer containing the memory location at the beginning
>of the array. There is no such thing as a pointer to the whole
>array: that is a Pasqualische or Fortranian notion. Pointers, in
>C, only point to atomic or aggregate (structure/union) objects. I
>whole-heartedly agree that for some uses it is rather nice to use
>such things. That is why (excuse me while I put on my flak jacket
>and asbestos suit) C is not the only language in the world worth
>using...
C *can* refer to whole arrays.
If you really want to take the address of an array rather than just
mentioning the array try
struct ary {
int a[SIZE];
} arr1, arr2;
...
&arr1;
f(arr1);
arr1 = arr2;
In this case 'arr1' by itself is not a pointer-constant but represents the
whole array (really structure) and '&arr1' refers to a pointer to the whole
array. 'arr1.a' is the more familiar pointer-constant pointing to the first
element of the array, 'f(arr1)' passes the whole array to the function
f(), and 'arr1 = arr2' assigns the whole array.
SO WHO NEEDS PASCAL?
--Tom Stockfisch, UCSD Chemistry
More information about the Comp.lang.c
mailing list