Author: Matt Taylor
Date: 19:18:31 01/01/03
Go up one level in this thread
On January 01, 2003 at 20:50:32, Bruce Moreland wrote: >On January 01, 2003 at 19:28:01, Uri Blass wrote: > >>I agree. >> >>I think that in cases that you care about speed then it is more important to >>care first about speed of the logic and not about speed of C. >> >>It means that if you have a condition A&&B and it is usually wrong because of B >>then it may be better to change it to B&&A. >> >>It is something that the compiler cannot do by itself because the compiler is >>not going to take the risk that B can cause a crash when A is false and the >>compiler has no way to know that B cannot cause a crash. > >C is defined such that if you have (A && B), A will be evaluated first always. > >The case where you get undefined execution order is this one: > > func(A(), B()); > >The order in which A() and B() are called is undefined. > >bruce In a boolean condition like that, yes, C defines A to be evaluated first. However, consider the following conditional: x > 10 && !done In this case, the compiler CAN swap the order of evaluation because there are no side-effects. The compiler won't swap unless you profile, and even then it might not swap the order. Order of evaluation is a trivial optimization, though. -Matt
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.