Timeline for Is it bad practice to write code that relies on compiler optimizations?
Current License: CC BY-SA 3.0
3 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 16, 2017 at 15:40 | comment | added | supercat |
...the compiler might at its leisure behave as though x*y promotes its operands to some arbitrary longer type (thus allowing forms of hoisting and strength reduction that would change the behavior of some overflow cases). Many compilers, however, require that programmers either prevent overflow at all costs or force compilers to truncate all intermediate values in case of overflow.
|
|
Oct 16, 2017 at 15:34 | comment | added | supercat |
Unfortunately, a lot of compiler documentation does a poor job of specifying what is or is not guaranteed in various modes. Further, "modern" compilers writers seem oblivious to the combinations of guarantees that programmers do and don't need. If a program would work fine if x*y>z arbitrarily yields 0 or 1 in case of overflow, provided that it has no other side-effects, requiring that a programmer must either prevent overflows at all costs or force the compiler to evaluate the expression a particular way will needless impair optimizations vs. saying that...
|
|
Oct 15, 2017 at 22:22 | history | answered | jmoreno | CC BY-SA 3.0 |