C'mon, guys!

Guy Harris guy at sun.uucp
Sat Jun 14 17:00:43 AEST 1986


> 	When a function is called with an array as its argument, what 
> 	is passed is a pointer to the first element of the array.  
> 	That's all there is, there ain't no more.

Try

	When an array name is used in an expression, it is treated as
	a pointer to the first element of the array.

It doesn't just happen when an array name is used as an argument; that's
just a special case, since it's an expression.

The *only* other form of pointer/array interchangability is that a
declaration of a formal argument as an array of X is treated as a
declaration of that argument as a pointer to X.  No other declarations of
arrays are equivalent to declarations of pointers; this is the one that
seems to bite people.  If you declare an array of 20 "int"s in the module
that defines that array, and you want to make an external reference from
another module, do NOT call it a pointer to "int".  Call it an array of an
unspecified number of "int"s ("int x[]") if that module doesn't know the
size of the array.  Better still, call it an *external" array of an
unspecified number of "int"s ("extern int x[]") and your code will build
even on systems which don't have UNIX's "common block" model of external
definitions and references.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list