Just wondering: When I add restrict to a pointer, I tell the compiler that the pointer is not an alias for another pointer. Let's assume I have a function like:
// Constructed example
void foo (float* result, const float* a, const float* b, const size_t size)
{
for (size_t i = 0; i < size; ++i)
{
result [i] = a [0] * b [i];
}
}
If the compiler has to assume that result
might overlap with a
, it has to refetch a each time. But, as a
is marked const
, the compiler could also assume that a is fixed, and hence fetching it once is ok.
Question is, in a situation like this, what is the recommend way to work with restrict? I surely don't want the compiler to refetch a
each time, but I couldn't find good information about how restrict
is supposed to work here.