Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!amdcad!ames!nrl-cmf!cmcl2!adm!smoke!gwyn
From: gwyn@smoke.ARPA (Doug Gwyn )
Newsgroups: comp.unix.wizards
Subject: Re: Read-only literal strings
Message-ID: <8568@smoke.ARPA>
Date: 23 Sep 88 06:14:32 GMT
References: <145@taux02.UUCP> <870@yabbie.rmit.oz>
Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) )
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 16

In article <870@yabbie.rmit.oz> rcodi@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.