|
Alias Optimization (by address)
Two pointers that point to members of different arrays can not be aliases, even if the offsets within arrays are not known. Example:In the code fragment below, the specific objects pointed to by p and q are not known, but they are members of different arrays, and therefore can not be aliased. int a[], b[]; void f (int i, int j) { int *p, *q; int x, y; p = &a[i]; q = &b[j]; x = *(q + 3); *p = 5; y = *(q + 3); g (x, y); } Since p and q are not aliased, the second reference to *(q + 3) can be eliminated, as shown below. int a[], b[]; void f(int i, int j) { int *p, *q; int x, y; p = &a[i]; q = &b[j]; x = *(q + 3); *p = 5; g (x, x); } © 1990-2012 Nullstone Corporation. All Rights Reserved. |