Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!wuarchive!udel!haven!umd5!jupiter.astro.umd.edu!jjk From: jjk@jupiter.astro.umd.edu (Jim Klavetter) Newsgroups: comp.lang.c Subject: SUMMARY OF confusion with char *a and char a[NUM] Summary: thanks, summary, and followup question Message-ID: <7676@umd5.umd.edu> Date: 5 Dec 90 21:23:44 GMT References: <7656@umd5.umd.edu> <1990Dec4.214845.18949@ccu.umanitoba.ca> <28341@mimsy.umd.edu> Sender: news@umd5.umd.edu Reply-To: jjk@astro.umd.edu (Jim Klavetter) Distribution: na Organization: U of Md., Astronomy Program Lines: 46 Thanks everyone for the end of confusion. In addition to the typos (NUM+1 and ":"), it was made abundantly clear to me that you can't use a "constant" as an lvalue: char a[NUM]; char *b; /* malloc b for NUM things */ a=strchr(string, ':'); /* ERROR */ b=strchr(string, ':'); /* CORRECT */ Of course I knew that and I shouldn't have had to post to the net. However, the following is ok in both cases (same declarations as above): strcpy(string, a); strcpy(string, b); Again, it was explained to me that a is "promoted" to type char*. Or another way it was put was the usual "equivalence" of pointers and arrays (and this is what the faq list details). I guess my followup question is more theoretical in nature: is this a good thing? Why shouldn't strcpy(string, a); also send an error message since the man page explicitely says that a (in this case) is char*. Conceptutually I understand that a copy (in this case) is fundamentally different than an equivalence (as above with strchr()), and also that a is unambiguous in this case, but as so many are willing to point out: pointers are not arrays! (and vice versa). Thus, the man page is asking for a pointer, but I am giving it an array, yet it works. I hope I am making my confusion a little clearer, here. It is not that I don't understand the difference between pointers and arrays, but that the language itself, IN SOME CASES, doesn't seem to think there is any difference. I'm certainly not a c basher, it just seems as if this is an inconsistency. Thanks once again for all the help, and I hope that this doesn't produce TOO many flames. jjk@astro.umd.edu Jim Klavetter (accepting mail for Athabasca and Reudi) Astronomy UofMD College Park, MD 20742 Brought to you by Super Global Mega Corp .com