Article View: comp.std.c
Article #3963Re: Placement of string literals
From: Zefram
Date: Sat, 09 Sep 1995 12:13
Date: Sat, 09 Sep 1995 12:13
19 lines
1504 bytes
1504 bytes
John Winters <john@polo.demon.co.uk> wrote: >In article <1995Sep7.094751.4404@dcs.warwick.ac.uk>, >Zefram <A.Main@dcs.warwick.ac.uk> wrote: >>Indeed. That's the effect of the const. > >Not quite. That's the effect of them being two identical string literals. >The compiler is entitled to coalesce the string literals >whether or not the things pointing to them are const. (Or perhaps >you meant one of the later consts?) I meant that the implementation you showed is permitted because the objects in question (arrays of characters) are const. The way I wrote it, with separate arrays, it could still be implemented the way you wrote it. My point is that string literals are effectively arrays of const char, which is what permits the compiler to coalesce identical strings. Though they have type char *, they are effectively const char *, as if they were all implicitly cast to char *. -zefram
Technical Details
Message-ID:
<1995Sep9.121334.29183@dcs.warwick.ac.uk>Path:
arc1-ca.pugleaf.net!news.dcs.warwick.ac.uk!not-for-mailReferences:
<42c4uu$9e5@sparcserver.lrz-muenchen.de> <DEG3zz.66q@polo.demon.co.uk> <1995Sep7.094751.4404@dcs.warwick.ac.uk> <DEJn1p.A5o@polo.demon.co.uk>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!news.dcs.warwick.ac.uk!not-for-mail From: A.Main@dcs.warwick.ac.uk (Zefram) Subject: Re: Placement of string literals X-Nntp-Posting-Host: stone Message-ID: <1995Sep9.121334.29183@dcs.warwick.ac.uk> Keywords: string literals, const Sender: news@dcs.warwick.ac.uk (Network News) Organization: Department of Computer Science, Warwick University, England References: <42c4uu$9e5@sparcserver.lrz-muenchen.de> <DEG3zz.66q@polo.demon.co.uk> <1995Sep7.094751.4404@dcs.warwick.ac.uk> <DEJn1p.A5o@polo.demon.co.uk> Date: Sat, 9 Sep 1995 12:13:34 GMT