Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #89749
| Path | csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: Order of addresses of string-literals inside a translation unit |
| Date | Tue, 14 Mar 2023 08:48:12 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 31 |
| Message-ID | <861qlr8hc3.fsf@linuxsc.com> (permalink) |
| References | <tt55du$1h8fk$1@dont-email.me> <6pzJL.248610$PXw7.31730@fx45.iad> <tt6rto$1pkqc$3@dont-email.me> <86356vatqg.fsf@linuxsc.com> <30469775-87ed-4cad-a4d0-05f0d6539c0bn@googlegroups.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | dont-email.me; posting-host="6c44312fb80ea20893bf6ca627665d05"; logging-data="431622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4SPkUJjXZP5bLz0DJA/jAEhHtXKSi8sc=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:YrV/97uxiqfurGBKii6lBeqhX38= sha1:TtEBVBMm3Aq6R+WsN/0PaxkjqpM= |
| Xref | csiph.com comp.lang.c++:89749 |
Show key headers only | View raw
"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> writes: > On Friday, February 24, 2023 at 11:55:33?AM UTC-5, Tim Rentsch wrote: > >> James Kuyper <james...@alumni.caltech.edu> writes: >> >>> Note, in particular, that because writing to the memory allocated to >>> store the string corresponding to a string literal has undefined >>> behavior, it's entirely permissible for an implementation to make all >>> occurrences of "Hello, world!" in a given program point at the same >>> location in memory, and to make "Hello, world!" + 7 == "world!". Both >>> optimizations have actually been implemented by many implementations. >> >> It's true that two or more string literals may have some bytes in >> common, but that's not because writing to a byte in a string >> literal has undefined behavior; it's because there is an explicit >> statement in the C++ standard (and also the C standard) that allows >> it. If anything the implication goes the other direction: because >> pre-standard C implementations stored multiple string literals in >> the same memory, when C was standardized it was pretty much a >> necessity that storing into the bytes of a string literal had to >> be undefined behavior. > > True. But the fact that storing into the bytes of a string literal > has undefined behavior is what makes storing multiple string > literals in overlapping memory workable. We're really saying the > same thing, from two different points of view. Your earlier statement has causality going in one direction, and mine has it going in the opposite direction. I'm hard pressed to see how those two views can be thought of as the same thing.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Order of addresses of string-literals inside a translation unit Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-22 14:31 +0100
Re: Order of addresses of string-literals inside a translation unit Richard Damon <Richard@Damon-Family.org> - 2023-02-22 20:34 -0500
Re: Order of addresses of string-literals inside a translation unit James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-23 00:00 -0500
Re: Order of addresses of string-literals inside a translation unit Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-23 13:52 -0800
Re: Order of addresses of string-literals inside a translation unit Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 09:03 -0800
Re: Order of addresses of string-literals inside a translation unit Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 08:55 -0800
Re: Order of addresses of string-literals inside a translation unit "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2023-02-24 09:43 -0800
Re: Order of addresses of string-literals inside a translation unit Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-14 08:48 -0700
Re: Order of addresses of string-literals inside a translation unit Öö Tiib <ootiib@hot.ee> - 2023-02-22 23:59 -0800
Re: Order of addresses of string-literals inside a translation unit scott@slp53.sl.home (Scott Lurndal) - 2023-02-23 16:18 +0000
csiph-web