pointers to arrays
Stuart D. Gathman
stuart at bms-at.UUCP
Wed Nov 19 06:07:40 AEST 1986
I am still confused about several things concerning pointers to arrays.
There does seem to be such a type, even in K & R.
1) How does one get such an animal? The only methods I can figure are
a) a cast: ( type (*)[] ) array_of_type
b) a function returning such a type (but the return must use a cast!)
2) The SysV semop(2) is defined as:
int semop(int,struct sembuf **,int)
but in the lint library as:
int semop(int,struct sembuf (*)[],int)
The semop(2) definition is definitely wrong. The lint definition
is possibly correct. I have ended up pretending it is:
int semop(int,struct sembuf *,int)
Am I really supposed to write the code like this:?
struct sembuf s[5];
. . .
rc = semop(sid,(struct sembuf (*)[])s,5)
3) It seems to me that any distinction between a pointer to an array
and a pointer to its first element is purely semantic. (And given
the semantic difficult of obtaining a pointer to an array, why use
them?) There is no pointer conversion that I can imagine involved.
4) Given:
TYPE **foo, (*bar)[];
both **foo and **bar refer to an object of type TYPE. Perhaps
this is the source of the error in the SysV documentation.
* * *
When are pointers to arrays appropriate?
Is there an easier (and more natural) way to use them in an expression?
--
Stuart D. Gathman <..!seismo!{vrdxhq|dgis}!bms-at!stuart>
More information about the Comp.lang.c
mailing list