[comp.lang.c] array names and pointers

gurgle@well.sf.ca.us (Pete Gontier) (10/02/90)

I need a lesson in the semantic differences between passing the name of an
array and passing a pointer to the type of that array. In other words, how
does the following usage differ?

	typedef char Str255 [ 256 ];

	Str255 s;
	char * s;

	void pstrcpy ( char * source, char * target ) {
	}

	void main ( void ) {
		Str255 target;
		pstrcpy ( "\ptest", target );
	}

Don't worry; I know very well that this won't compile. I wish it would.
Figuring out why it won't (or why it "shouldn't") is my intent here.

Please reply by mail; if I get non-trivial answers, I will summarize and
post them.
-- 
 Pete Gontier, gurgle@well.sf.ca.us
 Software Imagineer, Kiwi Software, Inc.

throopw@sheol.UUCP (Wayne Throop) (10/12/90)

> I need a lesson in the semantic differences between passing the name of
> an array and passing a pointer to the type of that array. In other
> words, how does the following usage differ?   [..code omitted..]

The above brings four questions to mind.

  1) What is meant by "passing the name of an array"?  Now this
     pretty clearly means "using the name of an array object as an
     actual parameter", but why not just say "passing an array"?
     Saying "passing the name of" makes me think of by-name binding, or
     of something else exotic.  (I know, the phrase "passing an array"
     is misleading in C, because of the conversion of arrays to
     addresses in value contexts.  But even so...)

  2) What is meant by "passing a pointer to the type of that array"?
     It may well mean "passing the address of an object of the type of
     elements of that array", but I'm even less sure of this one. 
     Mainly, just what a "pointer to the type of an array" might be
     is obscure... perhaps this is inside a compiler or an interpreter?
     As in "pointer to name of", "pointer to type of" makes me think
     of something more exotic than was probably intended.

  3) How does the following usage differ from what?  Or maybe this
     means "how do these two usages differ"?  I'm so confused.

and finally

  4) I wonder if the FAQ list needs a "glossary" section, so that if
     the above usages are well known, I can learn them, or if they are
     not, others can adopt better-known usages.  I know the FAQ already
     is careful to describe terms related to null pointers... perhaps
     it ought to recommend other usages as well.

     Just a thought.  Fry me gently if I'm just being silly.

( And in case anyone wondered, "using the name of an array object as
  an actual parameter" is, in fact, a subcase of "passing the address 
  of an object of the type of elements of that array". That is, the
  former is one way of accomplishing the latter. )
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org