Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!linus!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: Re: More on pointers/arrays: Function Arguments Message-ID: <665@bbncca.ARPA> Date: Wed, 11-Apr-84 15:30:56 EST Article-I.D.: bbncca.665 Posted: Wed Apr 11 15:30:56 1984 Date-Received: Thu, 12-Apr-84 01:31:08 EST References: <215@harvard.UUCP> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 34 ------------------------------ Dave Brownell (sequoia!brownell) gives an example of code of the sort foo(s) char s[]; { . . . ++s; /*AARGH*/ } and objects to the ++s because "arrays are not lvalues" and ++ is explicitly defined as "++ lvalue". The given code is actually correct, although poor style, because of the following, from the last paragraph of section 10.1 of the C Reference Manual (p. 205 of K&R) Also, since a reference to an array in any context (in particular as an actual parameter) is taken to mean a pointer to the first element of the array, declarations of formal parameters declared "array of ..." are adjusted to read "pointer to ...". Somewhat more clearly put, perhaps, though not part of the language definition, is the sentence on page 95 of K&R which says "As formal parameters in a function definition, char s[]; and char *s; are exactly equivalent;" What this means is that in the context of the function foo(), above, s is not an array, it is a pointer, and is thus an lvalue. This one case of the equivalence of s[] and *s is also the source of the recently discussed confusion when people try to use them equivalently other than in parameter declarations. -- Morris M. Keesan {decvax,linus,wjh12,ima}!bbncca!keesan keesan @ BBN-UNIX.ARPA