4 ms·
If you know C++, do you also know that `a[i] = i++` is UB... but only until C++17? If not, I hope that answers the question. That's one of the reasons some new
by aldanor 6y ago
If you know C++, do you also know that `a[i] = i++` is UB... but only until C++17? If not, I hope that answers the question.
That's one of the reasons some newer languages like Rust purposefully avoided increment operators, where instead you just do `x += 1` (and the add-assign operator doesn't return anything) or `x = x + 1`.
- beagle3 6y agoC has lots of undefined behavior unrelated to ++ (which only adds a small twist in the grand scheme of things). In C afaik f(g(),h()) is still UB because either g() or h() could be called first. ++ is just another small detail. (And no, I didn’t know C++17 made that behavior defined. Do you have a quick description of how it is defined now?) “Newer languages like rust” - just say “rust”, unless you have another good example of a non fringe language that adopted most c syntax including += but without ++.
- bregma 6y ago`f(g(),h())` is not UB. The order of evaluation of parameters is unspecified, but it's not undefined. They will be evaluated in some order before the call to `f()` takes place. If both functions modify the same global state, the order of modification is unspecified. It's still not undefined, and your use of global variables is still not recommended.
- gonzus 6y agoZig did too.