+ 3
What is the reason for running ++X an unexpected way?
Why does any of these options work here in Sololearn C ++ - but it doesn’t work for example in Visual Studio 15 C ++ and not only ... ??? https://code.sololearn.com/cuFUVy3QdHFR/#cpp Result from Visual Studio 2015 (not true of course): 7 -> 7 -> 7 -> 7 -> 7 -> 7 7 -> 7 -> 7 -> 7 -> 7 -> 7 7 -> 6 -> 7 -> 6 -> 7 -> 6 2 -> 1 -> 1 -> 1 -> 1 -> 1 2 -> 3 -> 4 -> 5 -> 6 -> 7 Result from SoloLearn SandBox (true): 2 -> 3 -> 4 -> 5 -> 6 -> 7 2 -> 3 -> 4 -> 5 -> 6 -> 7 2 -> 3 -> 4 -> 5 -> 6 -> 7 2 -> 3 -> 4 -> 5 -> 6 -> 7 2 -> 3 -> 4 -> 5 -> 6 -> 7 optimization ? C++ compiler version ? Statdart C++ ? ???
7 Antworten
+ 2
Undefined behavior.
"Modifying an object between two sequence points more than once produces undefined behavior".
https://en.wikipedia.org/wiki/Undefined_behavior
https://www.geeksforgeeks.org/undefined-behavior-c-cpp/
+ 3
There is no problem in fact.
It just got interesting - Thanks.
+ 2
Thanks.
I knew about the incorrectness of attempts to do this ... it was interesting here: is it possible to somehow stabilize it, for example, with the compilation option ... But such an idea arose when I saw that this particular SoloLearn example of sandboxes works stably.
+ 2
So no one answered - why does the sandbox always work in SoloLearn like it does not work anywhere? Perhaps this is a question for the developers of the C ++ environment for SoloLearn?
+ 1
https://en.cppreference.com/w/cpp/language/eval_order
"Order of evaluation of any part of any expression, including order of evaluation of function arguments is unspecified. The compiler can evaluate operands and other subexpressions in any order, and may choose another order when the same expression is evaluated again."
+ 1
Wasn't the definition of UB even stricter?
Like: Modifying an object between two sequence points only once but using it a second time can already lead to issues?
+ 1
Well, it does show the same output as on sololearn in visual studio 2019 with the c++17 or c++2a flag set.
But gcc has always been the odd one out with all the c++ extensions to be honest. :)