pointers for speed

Christopher R Volpe volpe at camelback.crd.ge.com
Wed Feb 27 01:18:38 AEST 1991


In article <955 at caslon.cs.arizona.edu>, dave at cs.arizona.edu (Dave P.
Schaumann) writes:
|>In article <1998 at gold.gvg.tek.com> shaunc at gold.gvg.tek.com (Shaun
Case) writes:
|>>I know that when you repeatedly access something like
|>>
|>>foo.a.b.c.d[11].value
|>>
|>>it is better to declare a (register) pointer, assign it the address
|>>of foo.a.b.c.d[11].value, and do manipulations on that, since it
|>>is faster.
|>
|>Oh really?  Seems to me that &foo.a.b.c.d[0] is a constant that can be
|>computed *at compile time*.  

Oh really? What if the type of "foo.a.b.c.d" is "struct bar *" and you
initialize it with:
    foo.a.b.c.d = (struct bar *) malloc(15 * sizeof(struct bar));

Then neither &foo.a.b.c.d[0] nor &foo.a.b.c.d[11] are compile time
constants.                        
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.std.c mailing list