Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site watmath.UUCP
Path: utzoo!watmath!kpmartin
From: kpmartin@watmath.UUCP (Kevin Martin)
Newsgroups: net.lang.c
Subject: Read-only Strings, and the (const) cast
Message-ID: <9498@watmath.UUCP>
Date: Sat, 20-Oct-84 14:12:46 EDT
Article-I.D.: watmath.9498
Posted: Sat Oct 20 14:12:46 1984
Date-Received: Sun, 21-Oct-84 14:41:12 EDT
Organization: U of Waterloo, Ontario
Lines: 21

For strings being read-only by default, Yes, please!
Unfortunately, this is the sort of decision that can't be justified with
reasons

I don't really like the idea of the funny type cast, where
    (const) "abc"
gives a string in read-only storage. I dislike it because it is indeed
a funny type cast, in that the operand of the cast is affected, sort of.
The string "abc" is an array of char, but an array isn't an rvalue,
and type casts operate on rvalues. Taking the rvalue of an array
implicitly takes the address of the first element, so normally, the
above would be casting the (already constant) pointer to the 'a' into
a constant pointer to the 'a'. So far, so good. But this particular cast
has the strange side effect of making the 'a' itself (as well as the
"bc") read-only, rather than just affecting the pointer.

For the rare cases where a writeable string is wanted, it can
be made into a static initialized variable. This would also make it
obvious to someone reading the code that the program intends to alter the
string.
                    Kevin Martin, UofW Software Development Group