If you write statements like:
a[i] = b[i] + c[i];
...you might want to indicate to the compiler that a[i]
, b[i]
and c[i]
point to different places in memory, thus enabling various optimizations (e.g. vectorization). This can be done by adding a special keyword in their declaration:
float * __restrict__ a; // same for b and c
However, what do you do if instead of float
you are using a more complex object, say:
struct item {
float foo, bar;
};
Consider the following code:
float *a, *b;
item *c;
// ...
for (int i = 0; i < 42; ++i) {
a[i] = b[i] * c[i].foo + c[i].bar;
}
In the loop, the compiler does not care about c[i]
but rather about c[i].foo
and c[i].bar
. How can an equivalent assertion about pointer independence be declared in this case with respect to individual fields of the structure?