Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!thumper!ulysses!andante!princeton!udel!gatech!purdue!decwrl!tle.dec.com!rmeyers From: rmeyers@tle.dec.com.UUCP Newsgroups: comp.sys.amiga Subject: Re: Leo's ANSI C flame Message-ID: <8807010927.AA11844@decwrl.dec.com> Date: 1 Jul 88 09:27:09 GMT Organization: Digital Equipment Corporation Lines: 54 Tim Olson, tim@delirun.amd.com, took exception to my statement that Kernighan and Ritchie never guaranteed the string constants were modifiable: |Well, K&R say that string constants are type "array of characters", and |there is no such read-only restriction on this type. I don't find this argument too convincing. K&R also says that the constant 1L has type "long int." That type doesn't have any read-only restrictions. Does that really imply anything? |In fact, they went out of their way to allow such manipulation, because |they declared that *all* string constants, even when written identically, |are distinct. That K&R promised that all string constants were distinct is not sufficient to state that K&R promises that string constants can be written. It is fairly trivial to write a compiler that write locks string constants but makes them all distinct. K&R never promise that string constants can be modified. They never state it, and they show no examples of it. Personally, I find it interesting that they always refer to the beasts as "string constants" and the ANSI standard always refers to them as "string literals," a term less prejudicial about whether the string can be modified. I think that the ANSI standard is more willing to discuss the sordid uses of string "constants" than K&R. The real problem is here that K&R is not a formal definition of C. It leaves a number of questions unanswered (the reason that the ANSI C committee exists is not to either improve or "screw up" the language: it exists simply to provide a formal definition for it). For example, does K&R allow you to convert a pointer to a function to a pointer to an int? Does the existence of that capability imply that you can not have execute only code because you care free to write memory through int pointers? |Leo's argument that a compiler that optimized and assigned 16 to x for | | x = strlen("constant string"); | |would break if he modified the string at runtime is incorrect, because |there is no way to get a legal pointer to the string in the above |expression ("constant string" is distinct from any other string |constant). Good point! ---------------------------------------- Randy Meyers, not representing Digital Equipment Corporation USENET: {decwrl|decvax|decuac}!tle.dec.com!rmeyers ARPA: rmeyers%tle.dec.com@decwrl.dec.com