Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site hadron.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: break, continue, return, goto (net.religion.c) Message-ID: <70@hadron.UUCP> Date: Thu, 14-Nov-85 00:49:40 EST Article-I.D.: hadron.70 Posted: Thu Nov 14 00:49:40 1985 Date-Received: Fri, 15-Nov-85 08:29:46 EST References: <771@whuxl.UUCP> <516@busch.UUCP> <779@whuxl.UUCP> <521@busch.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Distribution: net Organization: Hadron, Inc., Fairfax, VA Lines: 44 Keywords: argument, array, pointer, *sigh* Summary: That was no array; that was my pointer! In article <521@busch.UUCP> dcm@busch.UUCP (Craig Miller) writes: > Today's C question: how come C won't let you increment a global, > static or automatic array name, but will let you increment an array > name that's a function argument? Film at 11. Craig, I hope you're not serious. You've been around this newsgroup (I thought) since the last time I wrote >= 100 ll on this subject. For those who weren't, the problem is that when one seems to pass an array as an argument in C: char name[128]; ... foofunc(name); ... foofunc(str) char str[]; { one isn't really. This is one case where C violates the Rule of saying what you mean. For historical reasons (see diatribe in archives), what is passed is the address of the first element of the array -- a pointer instead of the array! This is one reason (of two basic ones) that there is the confusing statement somewhere in K&R that pointers and array addresses are treated identically. In this case, a correct declaration of str would be: char *str; but I may just want to emphasize the array-ness of it [*sigh*]. In any case, an array is a set of values at a fixed location. we cannot change the value of that fixed location (name++) any more than we can change any other fixed value (foofunc++ or foofunc()++) or constant (1++ ?????). a pointer is a single pointer-size (not necessarily word) location in memory in which can be placed an address, such as the address of the beginning of that array. The pointer can be changed: in particular, it can be incremented and decremented (str++). More concisely: a pointer name represents an l-value. an array name doesn't. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}