A last word on arrays? Hah!

Joseph S. D. Yao jsdy at hadron.UUCP
Sun May 4 00:44:46 AEST 1986


In article <310 at dg_rtp.UUCP> throopw at 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 at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list