p[1] vs. *(p+1)

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Sat Sep 1 06:51:02 AEST 1990


In article <1990Aug31.190103.15043 at laguna.ccsf.caltech.edu> bruce at seismo.gps.caltech.edu (Bruce Worden) writes:
> In article <1745 at io.UUCP> prs at eng.ileaf.com (Paul Schmidt) writes:
> >I must confess that I use p[1] in these cases, and count on the compiler
> >to optimize for me.
> In a simple case like p[1] the compiler may well optimize, but then it isn't 
> a particularly time consuming operation.

Huh? p[1] means exactly the same thing as *(p+1). At least two compilers
here (neither pcc-based) do that translation as the very first step.
There's no ``optimization'' involved.

>    *p1++ = *a1++ * *b1++;  
>     p2[i] = a2[i] * b2[i]; 

Note that on vector machines the latter is much faster in a loop.

---Dan



More information about the Comp.lang.c mailing list