Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ucbcad!ucbvax!decvax!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: <1575@dg_rtp.UUCP> Date: Sat, 4-Apr-87 14:47:45 EST Article-I.D.: dg_rtp.1575 Posted: Sat Apr 4 14:47:45 1987 Date-Received: Sun, 5-Apr-87 21:58:27 EST References: <2479@dalcs.UUCP> <5916@mimsy.UUCP> <2491@dalcs.UUCP> Lines: 43 Xref: utgpu comp.lang.c:1476 comp.bugs.4bsd:273 > dalegass@dalcs.UUCP (Dale Gass)> >> chris@mimsy.UUCP (Chris Torek) >>> struct direct *(*namelist)[]; >> No: for there is no such thing. A declaration for a pointer to an >> array must specify the size of the array. In fact, what both the >> code and the manual *should* say is >> struct direct ***namelist; > I disagree with this. I think a pointer to an array need not specify the > array size. I'll stay out of the does-the-array-size-need-to-be-specified argument for the most part, though I will note in passing that K&R and H&S allow it to be absent, while draft X3J11 does not. Most compilers allow it to be absent, but some do not. Thus, the wise portability-minded, starndard-complient coder will avoid such constructs, and replace them with the equivalent pointer constructs. Which is where *I* disagree with Chris. 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)[], which is a pointer to an array of pointers, should be replaced by ***foo, which is a pointer to a pointer (or an array of pointers) to a pointer (or an array of pointers) is WRONG, WRONG, WRONG! Look at the memory layouts implied by these constructs. *(*foo)[] is talking about THREE kinds of objects. (1) A pointer, (2) an array, and (3) the objects that the array of pointers point to. ***foo, on the other hand, is talking about FOUR kinds of objects. (1) A pointer, (2) the pointer (1) points to, (3) the pointer (2) points to, and (4) {finally} the object that (3) points to. A completely and utterly different memory layout. Be careful folks. Pointers aren't arrays, and arrays are not pointers, and even the experts (such as Chris) can *sometimes* get confused as to where a [] declaration part can and should be simply replaced by a * declaration part. -- "I like you. You're warm and compassionate, like my father." --- Stingray (speaking to the "good cop" of a pair of poplicemen trying to get 'ray to "talk") -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw