c语言restrict没有起作用呢?
#include <stdio.h>#include <malloc.h>
int main(void)
{
int a[3] = {1,2,3};
int * restrict p1;
p1 = a;
printf("%d\n",p1[2]);
int b[3];
int * restrict p2;
p2 = b;
b[2] = 5;
printf("%d\n",p2[2]);
p2 = b;
int * restrict p3 = (int *)malloc(10*sizeof(int));//不能写成int restrict * p3 = (int*)malloc(10*sizeof(int));
int * p4 = p3;
p3[3] = 10;
p3[3] += 10;
printf("%d\n",p3[3]);
p4[3] = 11;
p3[3] += 10;
printf("%d\n",p3[3]);
printf("%d\n",p4[3]);
return 0;
}
结果:
3
5
20
21