Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #89291
| 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 | 2023-02-24 08:55 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <86356vatqg.fsf@linuxsc.com> (permalink) |
| References | <tt55du$1h8fk$1@dont-email.me> <6pzJL.248610$PXw7.31730@fx45.iad> <tt6rto$1pkqc$3@dont-email.me> |
James Kuyper <jameskuyper@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. Nitpick: a string literal need not be a string (as the C standard points out, in a footnote IIRC).
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