i'm using mingw32-gcc, c99 standard. pasted below code few edits article restrict
keyword - http://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-1314-fasselt-c-keywords-report.pdf. according author, "result one"
, "result two"
should different, when run it, they're same. i'm not getting compiler warnings. there settings 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 have stayed same?\n\n"); *b += *c; } int main() { int = 1, b = 2; update(&a, &b, &a); printf("result one: a, b = %d, %d\n", a, b); = 1; b = 2; // reset values update_restrict(&a, &b, &a); printf("result two: a, b = %d, %d\n", a, b); getchar(); return 0; }
from wikipedia.org:
if declaration of intent not followed , object accessed independent pointer, result in undefined behavior.
this line update_restrict(&a, &b, &a);
results in undefined behavior.
the results might same, , might not.