Compiler Optimizations Debate
Discussions center on whether compilers should or can optimize away code such as checks, stores, or functions, often debating issues like undefined behavior, side effects, and language semantics.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Not if there was a proper optimization pass while compiling.
Does this feature inhibit any kind of optimization that current compilers could perform?
Shouldn't the compiler be able to figure out that such an optimization is possible?
No, it is a language semantics issue. You can get the compiler to optimize it away today, if you're careful. But that's a bad user experience. You should be able to specifically request this semantic, and be sure it works.
Well, if it didn't, they could optimize the compiler by removing those optimizations. :)
So the compiler cannot always optimize...
I feel like a compiler is within its rights to optimize out that check if it so wishes, though.
wouldn't any compiler optimize this anyway?
It's weird to me that a post like this even needs to be written. Isn't it kind of obvious that it's highly problematic for the compiler to do this optimization because the function, generally speaking, may have side effects?
Well, the compiler says undefined behavior and optimizes it away :D