I'm using mingw32-gcc, with the C99 standard. I pasted below code with a few edits from an article about the restrict
keyword - http://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-1314-fasselt-c-keywords-report.pdf. According to the author, "Result One"
and "Result Two"
should be different, but when I run it, they're the same. I'm not getting any compiler warnings. Are there any settings that I'm missing?
#include <stdio.h>
void update(int* a, int* b, int* c)
{
*a += *c;
*b += *c;
}
void update_restrict(int* a, int* b, int* restrict c)
{
printf("*c = %d\n",*c);
*a += *c;
printf("\n*c = %d - ",*c);
printf("shouldn't this have stayed the same?\n\n");
*b += *c;
}
int main()
{
int a = 1, b = 2;
update(&a, &b, &a);
printf("Result One: a, b = %d, %d\n", a, b);
a = 1; b = 2; // reset values
update_restrict(&a, &b, &a);
printf("Result Two: a, b = %d, %d\n", a, b);
getchar();
return 0;
}