string sharing (possible bug?)

Bill Felton bfelton at ibm.net
Thu Dec 10 02:01:54 UTC 1998


At 05:48 PM 12/9/98 -0800, you wrote:
>You are correct in theory.  The real world is different though. 
>
>In practice most C compilers are lax about checking for this and don't
>produce more than a single read/write data segment.  For instance, I just
>tried that program on Solaris using gcc and it worked exactly as I expected.
>Not even a warning. Most good C++ compilers generate a warning at
>initialization warning that a non-const pointer was initialized pointing to
>a const object but then C++ is more strict and you can circumvent that check
>with a cast anyhow.
>
>This is a common (albeit little known) problem in most languages and its
>simply up to the programmer to not modify string literals.
>

This is interesting.  We typically arrived at this very decision when
discussing/
arguing the merits of making literals read-only in my VisualAge and
VisualWorks
classes:  ultimately, the programmer is responsible for knowing how his/her
system *really* works, theoretical considerations of proper behavior aside.
One abandons a language when the violations of theoretical considerations grow
too strong to be born.  Otherwise, one grumbles, or gives in and swaps
outlooks,
realizing that there is no such thing as "the one right way" to do X.
(*other, of course, than doing it purely with objects* ;-> )

Bill





More information about the Squeak-dev mailing list