K
Kaz Kylheku
Kaz Kylheku wrote:
)> That's freedom for the implementation.
)
) Who cares about freedom for the implementation?
Anybody who wants his code optimized properly by the compiler.
C programmers who want aggressive optimizations sometimes switch to
nonportable tricks.
Code should be as safe as possible by default.
Safety can be traded for speed in places in the software where this is
justifiable.
) What is the ratio of users to implementors?
Irrelevant given the above.
) Sanely constraining the evaluation order has the benefit of eliminating
) an entire class of bugs.
Not constraining the evaluation order has the benefit of making code
The evaluation order is greatly constrained already, by the sequential
evaluation of full expressions, and operators like &&.
Yet, compilers perform a great deal of reordering anyway.
Constraints in the abstract order are not barriers to optimization.
Even if the abstract order asserts that A must be evaluated before B,
all it means is that all the observable effects should be as if A
was evaluated before B.
It's up to the optimizer to discover that the effects will be the same
even if A is not evaluated before B.
A compiler which does not do this type of analysis is not commercially
viable.
So for instance, suppose it's better to generate function arguments
right to left. Given a function call like
foo(x, y, z, w);
where these are just non-volatile variables, all distinct, the order can still
be right to left, even if the abstract semantics say left to right!
Evaluating x, then y, has no observable difference versus the opposite order.
a lot more optimizable.
Proof?
Or perhaps you can ask your compiler vendor to add a flag to enforce
strict evaluation order.
Right, following the 90/10 rule. Safety is only needed in 10% of the
code, so only for these ``cold spots'' do we need to turn on safe options.