3 ms·
Nice. Simplest fix would be to introduce a local variable int c=*count before the loop. (which you also would do with a non optimizing compiler so the count cou
by andi999 4y ago
Nice. Simplest fix would be to introduce a local variable int c=*count before the loop.
(which you also would do with a non optimizing compiler so the count could be in a register.
- ncmncm 4y agoThe point, which they probably should have spelled out better, was that std::string contains a char* that aliases everything there might be a pointer to. It is often hard to prevent pointers being created to things; calling a function that takes a "T const&" argument, the compiler is typically obliged to assume that a pointer to the argument was taken and retained. So, the "*count" in the example is a stand-in for a zillion other things you would actually have written, and that would also be affected by aliasing assumptions.
- taneq 4y agoI've been coding commercially in C and C++ (not full time but pretty regularly) for over 20 years and I'm starting to think the simplest fix is to not use C or C++.