> With modern compilers, you don't generally need to bother with replacing
>
> for (i = 0; i < len; ++i)
> sum += array[i];
>
> with
>
> for (p = array, endp = array + len; p < endp; ++p)
> sum += *p;
>
> Any compiler worth its salt will do it for you in a microsecond - or might
> not, if it thinks it will be less efficient; performing the strength
> reduction yourself restricts the compiler's options.
The following loop is faster than array, both on hppa processors using g++,
pentium, celeron and pIII using both egcs and msvc++:
for (i=len, p=(array+i); i--; )
sum+=*--p;
Descending loops with pointer use have always shown to be faster than
arrays. I use them a lot in image processing.
The opther point is that you can't trust your compiler using its maximum
optimization level. It sometimes produces weired results, and you always
have to check the accuracy when, as an example, you're using egcs with -O9.
Regards,
Gabriel Bouvigne - France
[EMAIL PROTECTED]
icq: 12138873
MP3' Tech: www.mp3tech.org
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )