3 ms·
And even better, start reducing the list after it's complete, by pushing things like integer overflow into implementation defined; several uses of inc/decrement
by marcosdumay 3y ago
And even better, start reducing the list after it's complete, by pushing things like integer overflow into implementation defined; several uses of inc/decrement operators into compilation error; and etc.
- bluGill 3y agoI don't want integer overflow to be implementation defined though, I want it undefined so my compiler can optimize my code for the fact that I don't overflow my integers in the first place.
- SAI_Peregrinus 3y agoThe implementation can define the behavior on overflow to be the optimized behavior. Optimization and UB are orthogonal concepts.
- planede 3y agoImplementation defined is not much better than undefined. It only requires documenting the behavior, so compilers could just go like "here are all the optimizations that we apply on each target platform for each set of compiler flags". It's not very helpful, you might as well look at the source code of the compiler.
- SAI_Peregrinus 3y agoThat's still substantially better than undefined, where multiple runs of the same compiler version on the same source with the same settings are allowed to result in different behaviors. I suppose an implementation could define non-deterministic behavior, but that's unlikely and could be forbidden by the standard. That said, my overall point is that optimization does not rely on undefined behavior at all. It's commonly argued that it does, but there are languages without undefined behavior that have working optimizers, so it's clearly false. Some optimizations for C (and C++) currently depend on undefined behavior, but there's nothing inherent about that dependence.