I have trouble understanding what restrict
means in terms with calling functions with already restricted variables.
Wikipedia tells me:
The restrict keyword is a declaration of intent given by the programmer to the compiler. It says that for the lifetime of the pointer, only it or a value directly derived from it (such as pointer + 1) will be used to access the object to which it points.
I have these three example functions:
void a(int const *p1, int const *p2) {
...
}
void b(int *restrict p1, int *restrict p2) {
...
}
void c(int *p1, int *p2) {
...
}
and I would call them each from a function
foo(int *restrict p1, int *restrict p2) {
a(p1, p2);
b(p1, p2);
c(p1, p1+1);
}
which of them would keep the restrict
promise that function foo
declaration makes?
The three cases would be:
Function
a
doesn't modify anything, so that would surely hold.How about
b
, are the parameters to it "directly derived" from thefoo
's pointers? Am I braking the promise I'm giving infoo
declaration if I modify thep1
orp2
inb
?Does the situation change in
c
from the previous scenario if the parameters aren't restricted in any way, and I edit for example p2 inc
?