[reSIProcate] Minor suggestion to use ++i instead of i++

Alan Hawrylyshen alan at jasomi.com
Sun Nov 7 00:26:50 CST 2004


On Nov 6, 2004, at 14:41, Cullen Jennings wrote:

> I took the following program
>
> int main()
> {
>    int i,j;
>    j=0;
>    for( i=0; i<100; i++ )
>    {
>       j = j+5;
>    }
>
>    return j;
> }

Because 'i' is a simple built-in type -- your results are consistent 
with what I'd expect.

Now make 'i' an iterator with different (non-local) semantics. The 
compiler cannot optimize.

This is well documented by many respectable C++ gurus.  It isn't 
strictly necessary, but

	A::operator++(); (pre incr).

is generally much preferred to (the hackishly specified)

	A::operator++(int); (post incr)

Google Herb Sutter GoTW and post vs pre increment C++ for more.

I don't really care, it's just a tip to keep in mind.  For building 
enumerations or integers, you are completely correct.


Alan

--
a l a n a t j a s o m i d o t c o m




More information about the resiprocate-devel mailing list