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.

Show/hideUsage

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++.

Show/hideRestrictions

The declaration of intent is effectively a promise to the compiler that, if broken, results in undefined behavior.

Show/hideExample

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++;
}

Show/hideSee also

Copyright © 2007-2008, 2011 ARM. All rights reserved.ARM DUI 0376C
Non-ConfidentialID061811