i plus plus

Hiroko Terasawa Hiroko.Terasawa@stanford.edu
Tue, 13 May 2003 23:10:25 -0700


DID YOU LIKE THE SPACESHIP!?  =)


I got the reason why karnighan recommends us to use i++.

> for( i=0; i<10; i++ ) {;}  //this is slow but very clear
yes. 

> for( i=0; i<=10; ++i ) {;} //this is faster

No. you have to say:
for( i=0; i<10; ++i ) {;}  // at least with g++.
why? don't ask me. I'm surprised myself! Funny ANSI rules?

> i = 10+1; //loop 10 times... sorta confusing
> while( --i ) {;}	//this is fastest?

from my personal experience, isn't it faster to say 
if( --i >= 0) {;}
I tried it the other day, and while statement was extremely super-slow,
and I don't understand WHY. I'd kiss the person who explains me why. 

> I think maybe people use i++ becuase it is semantically simple... no 
> weird extra number stuff.

seems like better in portability as well. 

-- 
Hiroko Shiraiwa-Terasawa <Hiroko.Terasawa@stanford.edu>