Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!mintaka!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Literal Strings in C ( was Re: example of how toupper() works ) Message-ID: <18577@haddock.ima.isc.com> Date: 18 Oct 90 22:04:49 GMT References: <2466@ux.acs.umn.edu> <256@dcsun21.dataco.UUCP> Reply-To: karl@ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 17 In article <256@dcsun21.dataco.UUCP> amodeo@dcsun03.UUCP (Roy Amodeo,DC ) writes: >> char *duh = "Hello"; ... *duh = ... > >In the above segment of code, the literal string pointed to by 'duh' is >being modified in place. Is this portable according to the ANSI standard? No. String literals may be shared and read-only. (K&R 1 explicitly said otherwise, which was a botch; I choose to interpret it as having described a particular implementation rather than the language itself.) >What does current practice dictate on this? Some compilers make them writable and separate; others make them read-only and shared. The latter compilers usually have an option to yield the former behavior, since some existing code depends on it. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint