__restrict

就像restrict__declspec修飾詞, __restrict關鍵字用來指示符號不是目前範圍中的別名。 __restrict關鍵字與不同restrict __declspec修飾詞,以下列方式:

  • __restrict是只能在變數上有效的關鍵字和__declspec(restrict)才有效,在函式宣告和定義。

  • 當__restrict時,編譯器不會傳播變數中的 [無別名] 屬性。也就是說,如果您指派__restrict變數為非-__restrict變數,編譯器就不一定代表的非-__restrict變數不是別名。這是不同的行為restrict C99 規格的關鍵字。

一般而言,如果您會影響到整個函式的行為,最好是使用__declspec比關鍵字。

__restrict類似於restrict C99 規格,但__restrict可用於 c 或 c 的程式。

不支援的__restrict C++ 參考。 

注意事項注意事項

也有一個變數上使用靜態 (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 + + 關鍵字