Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!jarthur!ucivax!zardoz.cpd.com!dhw68k!felix!asylvain From: asylvain@felix.UUCP (Alvin E. Sylvain) Newsgroups: comp.lang.c Subject: Re: difference between 'char *arr' and 'char arr []' Message-ID: <151805@felix.UUCP> Date: 1 Oct 90 22:49:18 GMT Sender: daemon@felix.UUCP Reply-To: asylvain@felix.UUCP (Alvin E. Sylvain) Organization: FileNet Corp., Costa Mesa, CA Lines: 58 In article <0975@sheol.UUCP> throopw@sheol.UUCP (Wayne Throop) writes: >> From: kuan@iris.ucdavis.edu (Frank [Who me?] Kuan) >> Now, I always thought that "targ[]" and "char *targ" were equivalent. > >As an aside, I took a survey a while back about this. It turns out >that the reason for this frequent misconception is (essentially) >poor teaching and poor reference materials. Essentially teachers >TEACH people this, sometimes inadvertantly. I'd like to point out what is IMHO the ultimate source of confusion. I have quoted here from the *near original* K&R, "The C Programming Language", copyright 1978, 7th printing, page 93: '' 5.3 Pointers and Arrays In C, there is a strong relationship between pointers and arrays, strong enough that pointers and arrays should be treated simultaneously. ... [goes on to tell how pa[i] is identical to *(pa+i)] ... As formal parameters in a function definion, ------ ---------- -------- -------- char s[]; and char *s; are exactly equivalent; which one should be written is determined largely by ------- ---------- [emphasis mine] how expressions will be written in the function. ... '' Notice how technically, this is quite correct (heck, this is *bible* of C, it ought to be at least *technically* correct), but, unless you're a seasoned veteran, it's durnedably misleading. There is no discussion here that says you *can't* do this when defining extern's across function boundaries. My point here is that K&R devote three full pages to telling us how equivalent pointers and arrays are, but *only one line* telling us "oh, BTW, the two declarations are only identical in function formal parameter definitions". I liken it to saying, "oh sure, you can go through the green light! That's what the light is there for!" (14 pages of how to go through the green light deleted for brevity's sake) (whoops ... forgot to mention that nasty ol' *red* light! Why do we keep having these accidents at intersections? I know, lack of proper driver's ed!) I challenge anybody (seriously, I don't want to do the research myself) to find *one reference* in K&R that *explicitly* says you *can not* use pointer declarations in one function and _extern_ array declarations in another (and, of course, vice-versa). Assuming you can find it, why isn't it discussed at all in 5.3? (Only K&R can answer that one!) -- ------------------------------------------------------------------------ "I got protection for my | Alvin "the Chipmunk" Sylvain affections, so swing your | Natch, nobody'd be *fool* enough to have bootie in my direction!" | *my* opinions, 'ceptin' *me*, of course! -=--=--=--"BANDWIDTH?? WE DON'T NEED NO STINKING BANDWIDTH!!"--=--=--=-