Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!prls!pyramid!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: C'mon, guys! Message-ID: <4139@sun.uucp> Date: Sat, 14-Jun-86 03:00:43 EDT Article-I.D.: sun.4139 Posted: Sat Jun 14 03:00:43 1986 Date-Received: Sun, 15-Jun-86 04:21:25 EDT References: <200@pyuxv.UUCP> <1181@ncoast.UUCP> <350@dg_rtp.UUCP> Organization: Sun Microsystems, Inc. Lines: 28 > 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@sun.com (or guy@sun.arpa)