On Thu, 2006-05-18 at 10:22 +1200, Derek Smithies wrote: > Ok, > so do you agree then that the programmer is better to take the above > construct, rework it as two lines, and let the optimiser do what > optimisers do really well, and the resultant code will be just as fast ?
Most certainly. In both cases for most architectures a good loop optimiser will strength reduce the index operation into an autoincrement of an address register and use another register to shadow the variable i. Both cases will have a similar run time speed but the answer you get depends on the order the compiler decides to increment the address and to increment i. The two line case makes the ordering explicit and thus has the advantage of giving the expected result! Michael.
