Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Order of addresses of string-literals inside a translation unit Date: Fri, 24 Feb 2023 09:03:51 -0800 Organization: A noiseless patient Spider Lines: 26 Message-ID: <86y1on9ers.fsf@linuxsc.com> References: <6pzJL.248610$PXw7.31730@fx45.iad> <87lekooxri.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="3119ccfe80da58d8ce67bcaefec134df"; logging-data="2384418"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JlsS8xHNdwMqgrpr9BEtRkzZFR7JtcSs=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Qp3uafXrGBwFfBSTLPE4fq/IxLU= sha1:hL30bO1OHQXy360cXnL2fjvMKQ0= Xref: csiph.com comp.lang.c++:89292 Keith Thompson writes: [string literals may overlap] > The standard *could* have required that two occurrences of "hello" in > the same program must refer to distinct objects with unequal addresses > (and code could have taken advantage of that guarantee). But in fact it > explicitly says that it's unspecified. > > C++17 5.13.5p16 [lex.string]: > > Evaluating a string-literal results in a string literal object > with static storage duration, initialized from the given > characters as specified above. Whether all string literals are > distinct (that is, are stored in nonoverlapping objects) and > whether successive evaluations of a string-literal yield the > same or a different object is unspecified. [ Note: The effect > of attempting to modify a string literal is undefined. ? end > note ] > > I hadn't realized until now that the standard allows two evaluations of > the same string literal to refer to distinct objects (and it's difficult > to imagine an implementation choice that would make them distinct). IIANM the statement about two evaluations is present in C++ but not in C.