🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3907

Re: Placement of string literals

#3907
From: Tanmoy Bhattacharya
Date: Sun, 03 Sep 1995 15:42
27 lines
1837 bytes
In article <42c4uu$9e5@sparcserver.lrz-muenchen.de>,
ua302aa@sun2.lrz-muenchen.de (Kurt Watzka) writes: 
<snip>
|> In other words, what is wrong with the statement: "String literals
|> are arrays of const char, and hence may be placed in a read only 
|> region of storage, even if they are used to initialize a non const
|> char *"?

String literals are not arrays of const char. They are arrays of char,
unambiguously (6.1.4). They decay to `pointer to char' (and _not_ `pointer to
const char') whereby they can be assigned to both (char*) and to (const
char*) objects without _requiring_ any diagnostics.

They may however be placed in read only memory because (6.1.4) an attempt to
modify a string literal results in undefined behaviour. By the very nature of
undefined behaviour(3.16), they _need not_ be placed in read only memory: or
be so placed only if used in a context where a `const char[]' is allowed.

Cheers
Tanmoy
-- 
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID: <42cicp$aoa@newshost.lanl.gov>
Path: arc1-ca.pugleaf.net!qcd.lanl.gov!tanmoy
References: <42c4uu$9e5@sparcserver.lrz-muenchen.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!qcd.lanl.gov!tanmoy
From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
Newsgroups: comp.std.c
Subject: Re: Placement of string literals
Date: 3 Sep 1995 15:42:17 GMT
Organization: Los Alamos National Laboratory
Distribution: world
Message-ID: <42cicp$aoa@newshost.lanl.gov>
References: <42c4uu$9e5@sparcserver.lrz-muenchen.de>
NNTP-Posting-Host: qcd.lanl.gov
Keywords: string literals, const