In article <>,
Richard Harter <> wrote:
>
>Well, no, he isn't saying any such thing. You just made it up. The
>fact that evaluation order in C is left to the compilers has very
>little to do with optimization; it is a historical artifact that came
>from endorsing existing practice when the ANSI standard was put
>together.
Perhaps, but it can still have a lot to do with optimization.
Consider:
b = (sqrt(sin(x)*cos(x))) * a;
If the compiler can guess that a is very likely to be zero, and that the
left side is very likely to be expensive, and has no side effects, then
it can generate code that evaluates a first, and then decides whether
or not to evaluate the left side.
I realize that this is a contrived example, but the bottom line is
that C was intended to be a *fast* language, and not a *safe* language.
Why nail the compiler's foot to the floor if you don't have to.
(When I first heard about the C language, it was described to me
as a substitute for assembly language. I think that's the proper
attitude to take when deciding between fast and pedantic.)
--
-Ed Falk,
http://thespamdiaries.blogspot.com/