...
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 */ /* ... */ } |
Note that undefined behavior occurs only when a
is assigned to b
. There is no problem when a
and b
point to within the same array, because they point to non-overlapping objects.
Compliant Solution
One way to eliminate the undefined behavior is simply to remove the restrict-
qualification from the affected pointers.
...