Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #80555 > unrolled thread
| Started by | Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> |
|---|---|
| First post | 2021-06-24 16:50 +0200 |
| Last post | 2021-06-24 17:37 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.c++
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
| From | Kli-Kla-Klawitter <kliklaklawitter69@gmail.com> |
|---|---|
| Date | 2021-06-24 16:50 +0200 |
| Subject | If string::c_str() doesn't invalidate iterators ... |
| Message-ID | <sb2646$6um$1@gioia.aioe.org> |
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!
[toc] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2021-06-24 08:27 -0700 |
| Message-ID | <d47382b2-2b6f-40c1-bb3c-d89850da882an@googlegroups.com> |
| In reply to | #80555 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2021-06-24 17:37 +0200 |
| Message-ID | <sb28r5$4m4$1@dont-email.me> |
| In reply to | #80556 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web