D
dr.oktopus
Hello,
walking an array is a common construct in programming.
In C language, I see two common practises.
1:
for (p = array, pend = array + size ; p < pend ; ++p)
/* do something */
2:
count = size;
p = array;
while (count--) {
/* do something here */
++p;
}
In complex contests, keeping a count variable could
be more readable (IMO) than having a variable acting
as a sentinel for the array bound (I'm speking of pieces
of codes where array navigation is not from the start
to the end, or inside Duff's devices, for example).
My question is: is this code really inefficient than
first approach (since it has to dec a variable every
cycle, more than test it) or current cpus could handle a sort
of decrement and test instr that do it all at the same time?
Thanks,
wily
walking an array is a common construct in programming.
In C language, I see two common practises.
1:
for (p = array, pend = array + size ; p < pend ; ++p)
/* do something */
2:
count = size;
p = array;
while (count--) {
/* do something here */
++p;
}
In complex contests, keeping a count variable could
be more readable (IMO) than having a variable acting
as a sentinel for the array bound (I'm speking of pieces
of codes where array navigation is not from the start
to the end, or inside Duff's devices, for example).
My question is: is this code really inefficient than
first approach (since it has to dec a variable every
cycle, more than test it) or current cpus could handle a sort
of decrement and test instr that do it all at the same time?
Thanks,
wily