Read-only literal strings

Doug Gwyn gwyn at smoke.ARPA
Fri Sep 23 16:14:32 AEST 1988


In article <870 at yabbie.rmit.oz> rcodi at yabbie.rmit.oz (Ian Donaldson) writes:
>Anyway, my question is, why *does* the C compiler put literal strings
>into the data segment?  Surely literal strings are considered constants
>just like 123, 45.34e44, so they should be unchangeable at run-time.

Many programs use mktemp() with a string literal argument.
This is now considered nonportable, but why cause problems
for those programs by changing the rules unnecessarily?

>I rekon that the C compiler should put strings into the text
>by *default*, ...

No, it should perhaps put strings in a read-only data segment
(or better yet, a shared literal pool).  This is permitted by
the proposed ANSI C standard.  People should start fixing their
code NOW.



More information about the Comp.unix.wizards mailing list