__restrict
__declspec
( restrict
) 修飾子と同様に、__restrict
キーワードは (2 つの先頭の下線 '_') は現在のスコープではシンボルがエイリアス化されないことを示します。 __restrict
キーワードは、__declspec (restrict)
修飾子とは次の点で相違があります。
__restrict
キーワードは変数に対してのみ有効です。__declspec (restrict)
は関数の宣言と定義内でのみ有効です。__restrict
は、C99 で開始され、/std:c11
または/std:c17
モードで使用できる C のrestrict
と似ていますが、__restrict
は C++ と C プログラムの両方で使用できます。__restrict
が使用されていると、コンパイラは変数の非エイリアスのプロパティを伝達しません。 つまり、__restrict
変数を__restrict
ではない変数に割り当てる場合、コンパイラは引き続き non-__restrict 変数のエイリアス化を許可します。 これは C99 C 言語restrict
キーワードの動作とは異なります。
一般に、関数全体の動作に影響させたい場合は、キーワードよりも __declspec (restrict)
を使用します。
以前のバージョンとの互換性を確保するために、_restrict
は、コンパイラ オプション /Za
(言語拡張機能の無効化) が指定されていない限り、__restrict
の同意語です。
Visual Studio 2015 以降では、C++ 参照で __restrict
を使用できます。
Note
volatile
キーワードも持っている変数に対して使用すると、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;
};
関連項目
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示