< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index Next in Thread >

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



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