7 Respostas
+ 3
For cpp see the "Examples" section in the documentation: https://en.cppreference.com/w/cpp/language/operator_incdec
16th Sep 2021, 3:09 PM
Lisa
Lisa - avatar
+ 7
In C, the order of evaluating this expression is not specified (therefore the compiler dependency). Not sure about Java, but a) there might be such a specification or b) some compilers might implement a specification. In any case, multiple increments in the same line don't make sense and I wouldn't rely on the compiler to fix it :)
15th Sep 2021, 11:51 AM
Lisa
Lisa - avatar
+ 6
Multiple increments in the same line is not a thing to do: It is undefined behavior and the result probably depends on the given compiler. That's what the warning is about to tell us. If the program compiles, the resulting value is rather a garbage value – the 7 in your example case isn't meaningful, it could have been a totally different one, I guess
15th Sep 2021, 11:30 AM
Lisa
Lisa - avatar
+ 3
Lisa Maybe you are right but it's interesting that 🅰️ at the end becomes 3️⃣ /it's correct after a triple incrementation/⁉️🤔
15th Sep 2021, 5:54 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 2
Lisa I didn't even see the warning until I scrolled down, it's been confusing me for a while
15th Sep 2021, 11:35 AM
Tim
Tim - avatar
+ 2
I still didn't get why 'undefined' error in C, If I do in Java I get A3, B6 without any warning.
15th Sep 2021, 11:38 AM
A͢J
A͢J - avatar
+ 1
Janusz Bujak 🇵🇱 Yes, I'm not sure if this is what we should expect – because it is already surprising that the program even reaches the output for incremented A. On the other hand, I'd guess it is not the process of incrementing itself that overtaxes the compiler. It's rather the chaining of the expressions (here addition) while the state of each term is indefinite. (Sorry, don't know how to express it better at the moment. Still need to think about if it makes sense at all 😅)
15th Sep 2021, 6:13 PM
Lisa
Lisa - avatar