Jack Klein <ja*******@spamcop.netwrites:
On Tue, 29 Jan 2008 05:56:28 +0000 (UTC), ro******@ibd.nrc-cnrc.gc.ca
(Walter Roberson) wrote in comp.lang.c:
[...]
>That's a good question to be asking, and the answer is NO, you
cannot exhaust memory that way. Constant string literals such as
"Circle" are guaranteed to exist for the life of the program
There are no such thing as "constant string literals" in C. The type
of a string literal is "array of char with static storage duration" in
C, and not "array of const char with static storage duration".
[...]
Yes, but keep in mind that, even though it's counterintuitive, "const"
and "constant" are quite different things. The "const" really means
read-only. For example, given:
int x = 42;
int *ptr = &x;
const int *const_ptr = &x;
const_ptr is a pointer to const int, so the int object can't be
modified via const_ptr, but it *can* be modified via x or *ptr.
A constant, on the other hand, is a lexical element such as an
integer, floating, enumeration, or character constant, and a constant
expression is an expression that can be evaluated during translation
(the definition is a bit more involved than that). What the language
calls a "string literal" could easily have been referred to as a
"string constant" if the authors of the standard had chosen that term.
But you're right that the standard uses the term "string literal", not
"constant string literal" or "string constant". It's also true that a
string literal is not const (though attempting to modify it still
invokes undefined behavior).
--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"