The restrict
keyword is mainly used in pointer
declarations as a type qualifier for pointers. It does not add any new functionality. It
is only a way for the programmer to inform the compiler about an optimization that
compiler can make. When you use restrict
with a pointer
(ptr), it tells the compiler that ptr is the only way to access the object pointed at,
and the compiler does not need to add any additional checks.
If a programmer uses the restrict
keyword and
violates the above condition, the result is an undefined behavior. The following is
another example with pointers that by default have no aliasing.
Apply the restrict
keyword for
performance improvement. The following example shows no memory dependencies with other
pointers.