3 ms·
On some pointers, for example function return types, restrict is defined to be meaningless. Also, restrict pointers can be copies of other pointers, and copies
by cliffbean 13y ago
On some pointers, for example function return types, restrict is defined to be meaningless. Also, restrict pointers can be copies of other pointers, and copies can be made of restrict pointers, subject to certain rules. So it's more involved than just "nothing aliases the pointer".
Here's another example:
// C has pretty paltry array support, so it's common for
// people to build their own stuff like this:
struct Array {
float *data;
size_t len;
};
// But then you use it:
void foo(Array *a, Array *b) {
for (i = ...)
for (j = ...)
a->data[i] = b->data[j];
}
and there's nowhere you can put restrict to declare that the two array references here are independent. The data pointer is one of the contexts where restrict is defined to be meaningless.
If you're a hyperactive squirrel, you might try rewriting all your code everywhere to do stuff like this:
void foo(Array *a, Array *b) {
for (i = ...)
for (j = ...) {
float *restrict x = a->data;
float *restrict y = b->data;
x[i] = y[i];
}
but then you'll just discover that most compilers ignore restrict in block scopes like this, because the semantics for that are tricky for compilers to deal with, so you still won't win.