Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!husc6!harvard!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: A last word on arrays? Hah! Message-ID: <389@hadron.UUCP> Date: Sat, 3-May-86 10:44:46 EDT Article-I.D.: hadron.389 Posted: Sat May 3 10:44:46 1986 Date-Received: Tue, 6-May-86 06:05:42 EDT References: <4992@think.ARPA> <310@dg_rtp.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 30 Keywords: array, reference, parameter, struct Summary: Nitpicking? Maybe, but let's be clear. (Array as arg) In article <310@dg_rtp.UUCP> throopw@dg_rtp.UUCP (Wayne Throop) writes: [attribution removed] >I do have comment on John Rose's proposals. ... >> (3) Interpret current C practice of converting array arguments >> to pointers as passing them by reference; make sizeof() >> work consistently. > >Well. Sizeof is indeed peculiar. For example, >sizeof(formal_array_name) yeilds your machine's pointer size. Ouch. First off (see that nit?), it took me two (admittedly fraction-of-a-second) passes to understand that you were talking about what sizeof yields [sp!] on an array declared as a formal a r g u m e n t . I spent at least half a sec wondering how you dressed your arrays to go formal! Second, though (if it's a nit, it's a MONSTER!), the reason it yields one of the pointer sizes of your machine is that there is no such thing, really, as an array argument. It's fairly clear that when you declare a formal argument to a function, the C compiler coerces it from array-of-X to pointer-to-X. You are therefore taking the size of a pointer, and it returns the size of that pointer (which size may depend on the type of the thing to which you are pointing). As usual, this has been discussed to death in earlier articles. If someone has a copy of my long-ish tutorial on this subject, please send it to me. I promise not to re-post it more often than every year or two, and flag it so you can junk it. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}