Could you explain me a bit how to use it?
I did a try:
Code:
#include <stdio.h>
int f(int *restrict x,int *restrict y, int *restrict z);
int main(void){
int a=5;
int b=3;
int *restrict p=&a;
int *restrict q=&b;
int *restrict r=&b;
int result=f(p,q,r);
printf("%d",result);
return 0;
}
int f(int *restrict x,int *restrict y, int *restrict z){
*y+=*z;
*x+=*z;
printf("%d\n",*x);
printf("%d\n",*y);
printf("%d\n",*z);
return (*x)*(*y)*(*z);
}
I did a mistake intentionally. Although I declared p and q as restrict both point to the same object.
I assumed the compiler will assume z was unchanged -because I declared it as restrict- and I will get a wrong result. However it works perfectly. So I don't understand how the compiler can be optimised with restrict if it doesn't assume it is changed?