...
In this noncompliant code example, assignments between restricted pointers in the file scope declarations assert that if an object is accessed using one of a
, b
, or c
, and that object is modified anywhere in the program, then it is never accessed using either of the other twosame scope is disallowed.
Code Block | ||||
---|---|---|---|---|
| ||||
int * restrict a; int * restrict b; extern int c[]; int main(void) { c[0] = 17; c[1] = 18; a = &c[0]; b = &c[1]; *a = *b; /* undefined behavior */ ... } |
Compliant Solution
One way to eliminate the undefined behavior is simply to remove the restrict-
qualification from the affected pointers.
Code Block | ||||
---|---|---|---|---|
| ||||
int * a; int * b; extern int c[]; int main(void) { c[0] = 17; c[1] = 18; a = &c[0]; b = &c[1]; *a = *b; /* valid defined behavior */ ... } |
restrict-qualified pointers Function Parameters
...