I often see people iterating over C style arrays using a pointer, while I find it more readable to use an index. The example below illustrates the two ways I think about. They do not lead to the same disassembly...
My question: Is it advantageous to use a "runner" instead of an index? By the way, is there another name for the "runner" technique?
Does it depend on the underlying type, e.g. int, char or a struct?
struct somestruct
{
float f;
int i;
};
const unsigned int uiSize = 10000;
somestruct * myarray = new somestruct[uiSize];
const somestruct * const pEnd = myarray + uiSize;
// way 1: runner
somestruct * pRunner = myarray;
while(pRunner < pEnd)
{
pRunner->f += 5;
pRunner->i += 5;
++pRunner;
}
// way 2: index
unsigned int ui = 0;
for (ui = 0; ui < uiSize; ++ui)
{
myarray[ui].f += 6;
myarray[ui].i += 4;
}