Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!rutgers!mcnc!rti!sheol!throopw From: throopw@sheol.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: Difference between "char *arr" and "char arr[]" Summary: read the faq Message-ID: <0975@sheol.UUCP> Date: 22 Sep 90 22:27:51 GMT References: <8103@aggie.ucdavis.edu> <1990Sep22.130345.15450@virtech.uucp> Lines: 37 > 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. My main suggestion to Frank Kuan is to read the "Frequently Asked Questions" posting when it comes around again. You will find the answer to the [] vs * question, along with a slew of other things that teachers (apparently) often mis-teach students. > From: cpcahil@virtech.uucp (Conor P. Cahill) > They are equivalent (with respect to referencing data) for just about all > cases EXCEPT for global variables. And automatic variables. And objects in the malloc/free heap. And variables with static visibility/persistence. I think that Conor may be taking "equivalent" to mean that the two objects can appear in lexically identical references. Which is correct. But the semantics which apply to the two cases are distinct. The fact is, there is only ONE place where the two are semantically equivalent, and that is as definitions of formal parameters. Again, see the FAQ for details, but code generated for subscripting, "sizeof" results, and in essence *everything* is different for these two declarations, with only the one exception. So, while Conor is technically correct, I think it is much more important to emphasize the differences here, rather than the similarities. The similarities are superficial, and the differences important, fundamental, and often overlooked. -- Wayne Throop !mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org