Restrict qualified pointers were explained to me as having a rule: Any object accessed by the pointer and modified anywhere is only ever accessed by the pointer. So the following does not work, right?
void agSum( int * restrict x, int n ){
for(int i=0; i<n-1; i++) x[i+1] += x[i];
}
int SumAndFree( int * restrict y, int n ){
agSum(y);
printf("%i",y[n-1]);
free(y);
}
So, I guess this is invalid because y[n-1] is modified somewhere not directly accessed from the restrict pointer y, and it is read by y.
If this is right, how can you call functions when the input pointer is restrict qualified? It seems like the function can't do anything without violating the restrict rule.
Is it another violation to free the restrict pointer? That is kind of a modification, I guess.
Thanks in advance!