Author: Dann Corbit
Date: 17:03:27 09/20/01
Go up one level in this thread
On September 20, 2001 at 18:24:07, Antonio Dieguez wrote: >can you tell me? Depends on a zillion things. Sometimes, you cannot make that translation. For instance, if you want to substitute & for &&, then you must have both operands be boolean (IOW: _ONLY_ take on the values 0 and/or 1). This is not a valid translation: int a = 1; int b = 2; if ((a && b) == (a & b) puts("My compiler is broken); If the cost of evaluating the operands is very high, then it may be better to use &&. Example: if (foo() && bar()) then foobar(); Suppose that foo() is fast, and bar() is really slow. Further, foo() is 0 most of the time. Then you would rather have the short circuit evaluation and branch. Missed branch predictions are expensive on newer chips, but it is not always an easy thing to see when one method is faster than the other.
This page took 0.01 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.