D
Dan Pop
In said:Umm no, I don't think so. I was merely following my instincts, which
invariably make me answer seemingly rhetorical questions.
According to the "as if" principle, a compiler is perfectly free to do
this given the right circumstances. And, in fact, it may just be the
clever thing to do.
But the point is that it can do it *only* when the program can't tell
the difference. Fortran programmers often wish they could do things
like:
if (a == 0 || b / a > 0) /* do something */ ;
The short circuiting feature of || and && is not an optimisation feature,
its purpose is to make the language easier to use. Without it, the
above statement would have to be rewritten as:
if (a == 0) /* do something */ ;
else if (b / a > 0) /* do it again */ ;
Dan