Various folks wrote: >>>>>> Compiler can optimize it any way it wants, >>>>>> as long as result is the same as unoptimized one. >>>>> >>>>> We have an option for that. It's called -O0. >>>>> >>>>> Pretty much all optimization will change the behavior of your program. >>>> >>>> Now that's a bit TOO strong a statement, critical optimizations like >>>> register allocation and instruction scheduling will generally not change >>>> the behavior of the program (though the basic decision to put something >>>> in a register will, and *surely* no one suggests avoiding this critical >>>> optimization). >>>> >>> Actually they will with multi threaded program, since you can have a case >>> where it works and now it is broken because one thread has speed up so much >>> it writes to a variable which had a copy on another thread's stack. >>> >> Why isn't that just a buggy program with wilful disregard for the use of >> correct synchronisation techniques? > > It is that, as well as a program that features a result that is different > from unoptimized code.
As a compromise, I'd vote that no optimizations may alter program behavior in any way not explicitly diagnosed in each instance of their application. (That way there's less likelihood of "surprises", and an increasing likelihood of productive correction of code and/or alternatively feedback encouraging either refinement or elimination of optimizations considered more likely counter productive than useful prior to them resulting in bugs in the programs previously verified as behaving as intended, although potentially relying on a behavior not warranted by the language's spec.)