How *restrict / *__restrict__ works in C / C++?

Posted by Moraru Lilian on Stack Overflow See other posts from Stack Overflow or by Moraru Lilian
Published on 2011-11-28T01:40:00Z Indexed on 2011/11/28 1:49 UTC
Read the original article Hit count: 302

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c