Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!seismo!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP Newsgroups: comp.lang.c,comp.bugs.4bsd Subject: Re: Bad Pointer Declaration in 'scandir' Message-ID: <1604@dg_rtp.UUCP> Date: Tue, 7-Apr-87 11:16:37 EST Article-I.D.: dg_rtp.1604 Posted: Tue Apr 7 11:16:37 1987 Date-Received: Fri, 10-Apr-87 04:31:16 EST References: <2479@dalcs.UUCP> <5916@mimsy.UUCP> <2491@dalcs.UUCP> <1575@dg_rtp.UUCP> <6145@mimsy.UUCP> Lines: 60 Xref: utgpu comp.lang.c:1504 comp.bugs.4bsd:280 >,>>> chris@mimsy.UUCP (Chris Torek) >> throopw@dg_rtp.UUCP (Wayne Throop) >>... Unusual as it is for Chris to make a mistake, he has made a >>doozy here (though an easy doozy to make, so to type). >>In particular, the claim that *(*foo)[] [...] should be replaced by ***foo >>[... is incorrect ...] > I did not (or I hope I did not) make such a claim. Rather, my > claim was that the type of `namelist' in scandir should have been > (struct direct ***): not (struct direct **[]), as it was in the > source and manual page; nor (struct direct *(*)[]), as was suggested > in the first article with this title. Ah. So, rather than Chris serving as an object lesson on how even experts can become confused, I myself serve as an object lesson on how newcomers to a conversation should pay closer attention to the preceeding discussion. But wait! Part of what confused me was that Chris didn't make totally clear how he got his result that (struct direct ***) was the correct type for the formal parameter! Here is a chance to further pontificate! > [...] I quote from > the comment immediately preceding the code to scandir() itself: > Returns the number of entries and a pointer to a list of > pointers to struct direct (through namelist). "A pointer to a ...." hmmmmm... let's construct the "correct" definition from the english description. a pointer to... * a list (array) of... (*)[N] (but with array-pointer equiv, this is just:) * pointers to... ** struct direct (struct direct **) That gives two stars so far, where does the third come from? Aha! from the "Returns [...] (through namelist)"! We need to explicitly pass the location of this (struct direct **), so that scandir can put a value in it! Hence, from the english, the correct type for the formal would be (struct direct ***) (or, if one allows the type (*)[] to represent "pointer to a list of" as Chris does not:) (struct direct *(**)[]) In ANY event, neither **[] nor *(*)[] are correct, just as Chris was trying to say all along. I think. -- I think. I think I am. Therefore I AM... I think. --- Moody Blues Cogito, ergo spud. I think, therefore a yam. --- anon -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw