次の方法で共有


__restrict

restrict __declspec 修飾子と同様に、__restrict キーワードは、現在のスコープではシンボルがエイリアス化されないことを示します。 __restrict キーワードは、restrict __declspec 修飾子とは次の点で相違があります。

  • __restrict キーワードは変数に対してのみ有効です。__declspec(restrict) は関数の宣言と定義内でのみ有効です。

  • __restrict が使用されていると、コンパイラは変数の非エイリアスのプロパティを伝達しません。 つまり、__restrict 変数を __restrict ではない変数に代入する場合、コンパイラは __restrict でない変数がエイリアス化されないことを前提としません。 これは C99 仕様の restrict キーワードの動作とは異なります。

一般に、関数全体の動作に影響を及ぼす場合、キーワードよりも __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++ キーワード