This enables the compiler to perform optimizations that might otherwise be prevented
because of possible aliasing.
In the following example, pointer
a does not, and must not, point to the
same region of memory as pointer
void copy_array(int n, int *restrict a, int *restrict b)
while (n-- > 0)
*a++ = *b++;
extern int array;
copy_array(50, array + 50, array); // valid
copy_array(50, array + 1, array); // undefined behavior
Pointers qualified with
restrict can however point to different
arrays, or to different regions within an array.
It is your responsibility to ensure that
pointers do not point to overlapping regions of memory.
__restrict, permitted in C90 and C++, is a synonym for
restrict to be used in C90