__restrict

restrict __declspec 修饰符, __restrict 关键字指示符号在当前范围内没有抗锯齿。 __restrict 关键字与 restrict __declspec 修饰符在以下方面有所不同:

  • __restrict 关键字才是有效的。变量,因此, __declspec(restrict) 才有效的函数声明和定义。

  • 当使用 __restrict ,编译器不会传播变量的非别名属性。 也就是说,如果将 __restrict 变量设置为非__restrict 变量,编译器不会提示非__restrict 变量未抗锯齿。 这与 restrict 关键字的行为不同从 C99 规范的。

通常,因此,如果影响整个函数的行为,使用 __declspec 比关键字最好。

__restrict 类似于从 C99 规范的 restrict ,但是, __restrict 可用于 C++ 或 C 程序。

未在 C++ 中 __restrict 支持引用。 

备注

当在还有 volatile (C++) 关键字的变量, volatile 将优先。

示例

// __restrict_keyword.c
// compile with: /LD
// In the following function, declare a and b as disjoint arrays
// but do not have same assurance for c and d.
void sum2(int n, int * __restrict a, int * __restrict b, 
          int * c, int * d) {
   int i;
   for (i = 0; i < n; i++) {
      a[i] = b[i] + c[i];
      c[i] = b[i] + d[i];
    }
}

// By marking union members as __restrict, tell compiler that
// only z.x or z.y will be accessed in any given scope.
union z {
   int * __restrict x;
   double * __restrict y;
};

请参见

参考

C++关键字