Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: qualified 1st NCCE behavior

...

Code Block
bgColor#FFCCCC
langc
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. 

...