Expert C Programming

(Jeff_L) #1

The popular belief is usually wrong. With modern production-quality optimizing compilers, there is
not necessarily a difference in the code generated for one-dimensional arrays and that for references
through a pointer. After all, array subscripts are defined in terms of pointers, so it is often possible for
the optimizer to make the transformation to the most efficient representation, and output machine
instructions for that. Let's take a look at those array/pointer alternatives again, and separate out the
initialization from an access in a loop:


int a[10], *p, i;


Variable a[i] can equally be accessed in any of the ways shown in Figure 9-2.


Figure 9-2. Array/Pointer Code Trade-offs
Free download pdf