>but (as I've read) pointer arithmetic is faster
Prove it. In your example, the two are quite likely compiled to exactly the same machine code. Array subscripting is literally syntactic sugar for the equivalent pointer offset calculation. A more likely example is this:
int x[N];
int *p = x;
for ( int i = 0; i < N; i++ )
process ( x[i] );
for ( int i = 0; i < N; p += i )
process ( *p );
The latter could very well be faster (though I would question why you're worried about such micro-optimizations) due to the fact that the body of the loop is only performing a dereference rather than an addition
and a dereference.
My advice is not to worry about it. Use whichever more clearly displays your intentions.
Last edited by Narue; Nov 9th, 2008 at 10:32 am.
New members chased away this month: 4