Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!hc!lll-winken!gauss.llnl.gov!casey From: casey@gauss.llnl.gov (Casey Leedom) Newsgroups: comp.windows.x Subject: Re: stupid C question Message-ID: <16124@lll-winken.UUCP> Date: 31 Dec 88 20:38:02 GMT References: <8812300028.AA17754@EXPO.LCS.MIT.EDU> <4543@xenna.Encore.COM> Sender: usenet@lll-winken.UUCP Reply-To: casey@lll-crg.llnl.gov.UUCP (Casey Leedom) Organization: Lawrence Livermore National Laboratory Lines: 26 | From: bzs@Encore.COM (Barry Shein) | | What's worse are compilers (known to exist!) which return sizeof(char *) | for sizeof(string constant), that is unacceptable but worth a moment's | thought when relying on these semantics or trying to track down a problem. Unacceptable in the sense that all C compilers that I know of return n+1 instead of sizeof(char *) giving us a ``common law'' standard, but the second interpretation is just as consistent as the first if not more so. K&R allows us to do both of the following: 1. char s[] = "..."; 2. char *t = "..."; Is "..." really just shorthand for ``{ '.', '.', '.' }'', or is it a directive to the compiler to find some space somewhere (n+1 in size) and then replace the reference to the double quoted object with a char * pointer to that space? Throughout C, there are in fact more instances of the second than there are of the first. I can pass "..." as an argument to a function and get the second interpretation, but not the first for instance. In some ways interpreting sizeof("...") to be sizeof(char *) would be more consistent, but certainly less useful. Casey