The restrict type qualifier

This type qualifier is introduced in the C99 standard. C++ onlyThe z/OS® XL C/C++ compiler supports it as an IBM extension. C++ only

A pointer is the address of a location in memory. More than one pointer can access the same chunk of memory and modify it during the course of a program. The restrict (or __restrict or __restrict__)1 type qualifier can be applied to a pointer type to form a restrict-qualified pointer. During the execution of the block that is associated with the declaration of an object that provides a way to designate a restrict-qualified pointer, the memory addressed via the restrict-qualified pointer cannot be modified or can be accessed only via this pointer if the pointer does not point to a const-qualified type. The compiler may choose to optimize code involving restrict-qualified pointers in a way that might otherwise result in incorrect behavior. It is the responsibility of the programmer to ensure that restrict -qualified pointers are used as they were intended to be used. Otherwise, undefined behavior may result.

If a particular chunk of memory is not modified, it can be aliased through more than one restricted pointer. The following example shows restricted pointers as parameters of foo(), and how an unmodified object can be aliased through two restricted pointers.
void foo(int n, int * restrict  a, int * restrict b, int * restrict  c)
{
    int i;
    for (i = 0; i < n; i++)
        a[i] = b[i] + c[i];
}
Assignments between restricted pointers are limited, and no distinction is made between a function call and an equivalent nested block.
{
      int * restrict  x;
      int * restrict  y;
      x = y; // undefined
      {
         int * restrict  x1 = x; // okay
         int * restrict  y1 = y; // okay
         x = y1;  // undefined
      }
   }
In nested blocks containing restricted pointers, only assignments of restricted pointers from outer to inner blocks are allowed. The exception is when the block in which the restricted pointer is declared finishes execution. At that point in the program, the value of the restricted pointer can be carried out of the block in which it was declared.
Notes:
  1. The restrict qualifier is represented by the following keywords (all have the same semantics):
    • The restrict keyword is recognized in C, under compilation with c99 or the LANGLVL(STDC99) or LANGLVL(EXTC99) options, and in C++ under the LANGLVL(EXTENDED) or KEYWORD(RESTRICT) options. IBM extension The __restrict and __restrict__ keywords are recognized in both C, at all language levels, and C++, at LANGLVL(EXTENDED). IBM extension