How *restrict / *__restrict__ works in C / C++?
- by Moraru Lilian
Here is some code I wrote:
#include <iostream>
using namespace std;
int main(void) {
int i = 7;
int *__restrict__ a = &i;
*a = 5;
int *b = &i, *c = &i;
*b = 8;
*c = 9;
cout << **&a << endl; //*a
return 0;
}
From what I've read, if I do " *a = 5 ", it changes the value of the memory he, "a", is pointing to, after that the memory to which he is pointing to should not be modified by anyone else except "a", which means that these program is wrong because "b" and "c" modify it after that.
Or, even if "b" modifies "i" first, after that only "a" should have access to that memory( "i" ).
Am I getting it correctly?