Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #80557
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: If string::c_str() doesn't invalidate iterators ... |
| Date | 2021-06-24 17:37 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <sb28r5$4m4$1@dont-email.me> (permalink) |
| References | <sb2646$6um$1@gioia.aioe.org> <d47382b2-2b6f-40c1-bb3c-d89850da882an@googlegroups.com> |
On 24 Jun 2021 17:27, Öö Tiib wrote: > On Thursday, 24 June 2021 at 17:51:03 UTC+3, Kli-Kla-Klawitter wrote: >> If string::c_str() doesn't invalidate iterators, I could access >> str[str.length()] safely myself even it's outside the bounds >> because the storage for the zero-termination must be pre-allocated >> to terminate the string in-place. Cooooooooooooooool! > > There are no such strange logic needed. The str[str.length()] is > required to return reference to null character after last character > of string. Modifying that null character using the reference is > undefined behavior. KKK has probably read some C++03 discussion. In C++03 the terminating zero in the buffer was only guaranteed via the `const` accessors. The guarantees were revamped for C++11 allegedly for thread safety (which I regard as a whole load of bollocks), but incidentally so that a design level error in the C++03 COW support was removed -- with that bathwater also containing the baby COW, but hey, no pain no gain. - Alf
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
If string::c_str() doesn't invalidate iterators ... Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> - 2021-06-24 16:50 +0200
Re: If string::c_str() doesn't invalidate iterators ... Öö Tiib <ootiib@hot.ee> - 2021-06-24 08:27 -0700
Re: If string::c_str() doesn't invalidate iterators ... "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-06-24 17:37 +0200
csiph-web