Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!vrdxhq!bms-at!stuart From: stuart@bms-at.UUCP (Stuart D. Gathman) Newsgroups: comp.lang.c Subject: pointers to arrays Message-ID: <273@bms-at.UUCP> Date: Tue, 18-Nov-86 15:07:40 EST Article-I.D.: bms-at.273 Posted: Tue Nov 18 15:07:40 1986 Date-Received: Tue, 18-Nov-86 22:05:49 EST Organization: Business Management Systems, Inc., Fairfax, VA Lines: 47 Keywords: What? Why? How? 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>