| |||
| Home > Language Extensions > C99 language features available in C++ and C90 > restrict | |||
The restrict keyword is a C99 feature. It enables you to convey a declaration of intent to the compiler that different pointers and function parameter arrays do not point to overlapping regions of memory at runtime. This enables the compiler to perform optimizations that can otherwise be prevented because of possible aliasing.
The keywords __restrict and __restrict__ are
supported as synonyms for restrict and are always available.
You can specify --restrict to allow the
use of the restrict keyword in C90 or C++.
The declaration of intent is effectively a promise to the compiler that, if broken, results in undefined behavior.
The following example shows use of the restrict keyword applied to function parameter arrays.
void copy_array(int n, int *restrict a, int *restrict b)
{
while (n-- > 0)
*a++ = *b++;
}
The following example shows use of the restrict keyword applied to different pointers that exist in the form of local variables.
void copy_bytes(int n, int *a, int *b)
{
int *restrict x;
int *restrict y;
x = a;
y = b;
while (n-- > 0)
*q++ = *s++;
}
New language features of C99 in Using the Compiler.