- What a bug - 9 Updates
Bonita Montero <Bonita.Montero@gmail.com>: Sep 02 06:19AM +0200 Am 01.09.2023 um 23:50 schrieb Chris M. Thomasson: > Try something like: I know that I could have done that easier, but I wanted to know where's the bug and why my example does find the key value anyway. > {"--realtime", 4 } > }; > auto mapped_opt = opts.find("--realtime"); The problem here is that each find creates a string-object, which is rather slow. |
Bonita Montero <Bonita.Montero@gmail.com>: Sep 02 06:23AM +0200 Am 01.09.2023 um 23:09 schrieb Alf P. Steinbach: > setup to compare pointers to string literals. That's because the Holy > Standard does not require string pooling. An easy fix is to use > `wstring_view` as key (for that include `<string_view>`). Exactly, that's what I did afterwards. But I first thought that my code works because the linker has joined my both "--high" strings to the same address. |
Muttley@dastardlyhq.com: Sep 02 10:25AM On Sat, 2 Sep 2023 06:23:02 +0200 >Exactly, that's what I did afterwards. But I first thought >that my code works because the linker has joined my both >"--high" strings to the same address. There's nothing in the standard saying that should be the case. I thought you were a C++ god? |
Bonita Montero <Bonita.Montero@gmail.com>: Sep 02 12:56PM +0200 >> that my code works because the linker has joined my both >> "--high" strings to the same address. > There's nothing in the standard saying that should be the case. No, but also nothing that forbids that. And actually the linkers do that. Try this at home: #include <iostream> int main() { std::cout << ("xxx" == "xxx") << std::endl; } Although MSVC joined the strings in my first example it doesnt do that in this example. Bug g++ and clang++ do join the strings. > I thought you were a C++ god? Sounds you are not. |
Bonita Montero <Bonita.Montero@gmail.com>: Sep 02 02:35PM +0200 Am 02.09.2023 um 12:56 schrieb Bonita Montero: > { > std::cout << ("xxx" == "xxx") << std::endl; > } I found a small imcompatibility between MSVC's cl and "MSVC's" clang-cl: C:\Users\Boni>cl -Ox -MD join.cpp -EHs ... C:\Users\Boni>join 0 C:\Users\Boni>clang-cl -Ox -MD join.cpp -EHs ... C:\Users\Boni>join 1 Maybe someone relies on the uniqueness or on the joining. |
Bonita Montero <Bonita.Montero@gmail.com>: Sep 02 02:41PM +0200 Am 02.09.2023 um 14:35 schrieb Bonita Montero: > C:\Users\Boni>join > 1 > Maybe someone relies on the uniqueness or on the joining. I found that there is a commandline-option of MSVC and clang-cl that directs the compiler to join strings with -GF or not with -GF-. For MSVC the default is not to join the strings, for clang-cl the default is to join the strings. |
Muttley@dastardlyhq.com: Sep 02 03:30PM On Sat, 2 Sep 2023 12:56:58 +0200 >>> "--high" strings to the same address. >> There's nothing in the standard saying that should be the case. >No, but also nothing that forbids that. There's nothing forbidding a lot of things but relying on them always being the case would lead to some interesting bugs when the code is compiled on a compiler that uses a different approach. |
Bonita Montero <Bonita.Montero@gmail.com>: Sep 02 06:10PM +0200 > There's nothing forbidding a lot of things but relying on them always being > the case would lead to some interesting bugs when the code is compiled on > a compiler that uses a different approach. I just wanted to verify what I did wrong with my unordered map, having a wchar_t-pointer as the key, and accidentally MSVC joined the strings and the key actually was found because the keys shared the addresses. So I this was all accidentally and I didn't rely on anything. But if you're stuck with MS cl or clang-cl and you use the -GF(-) switch correctly - as I said both have different defaults - you could even rely on that anyway if you're writing a Windows application. |
jak <nospam@please.ty>: Sep 02 11:15PM +0200 Bonita Montero ha scritto: > } > Why does my code have a bug and why doesn't mappedPrio > point to end() at the end? HI, you just need to use wchar_t in your search string as well: from: auto mappedPrio = opts.find( "--high" ); to: auto mappedPrio = opts.find( L"--high" ); |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment