Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <1703@auspex.auspex.com> Date: 26 May 89 19:02:30 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <13269@haddock.ima.isc.com> <96@elf115.uu.net> Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 51 >>I think the "second-classedness" of arrays helps give C its elegant >>syntax. Any other examples of the "problems" it causes? > >I think of C arrays as syntactic sugar for initialized pointers. In other words, your answer to his question is that one problem caused by the "second-classedness" of arrays is that it leads people to think of them, incorrectly, as pointers? I'd certainly agree with that.... >Thus > > char foo[] = "I am an anonymous char *"; > >is an abbreviation for > > register char *const foo = "I am an anonymous char *"; > >I reason 'const' because the value of the pointer cannot be changed, >and 'register' because the address of the pointer cannot be taken. Well, unfortunately, there's no little thing you can add to the declaration to straightforwardly reflect the fact that: foo.c: ... char foo[] = "I am an array"; ... bar.c: ... extern char *const foo; ... is wrong. (And yes, "I did (the above); why isn't it working?" has appeared as a question in this newsgroup in the past, so people really *do* get the idea that it's supposed to work.) If you really want to go out of your way, I guess the "register" does that - but it also hints that something gets stuffed into a register, which is wrong. Think of arrays as arrays, pointers as pointers, and array-valued expressions being converted, in most but *not* all contexts, as being converted to pointer-valued expressions that point to the first element of the array, and you won't go wrong. That may be more *complicated* than your model, but it has the advantage of reflecting reality....