我正在看pthread_create的手冊頁。pthread_create中的restrict是什麼意思
int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg);
這個函數簽名中的'restrict'是什麼意思?它的目的是什麼?
我正在看pthread_create的手冊頁。pthread_create中的restrict是什麼意思
int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void*), void *restrict arg);
這個函數簽名中的'restrict'是什麼意思?它的目的是什麼?
restrict
在調用者上要求該函數的指針參數不能別名。也就是說,指針不能指向同一個對象。
雖然這對於pthread_create
有明顯意義,但對於像memcpy
這樣的函數更重要。
void * memcpy(void *restrict s1, const void *restrict s2, size_t n);
memcpy
要求輸入緩衝器不重疊。它通常作爲一個簡單的向前或向後迭代循環來實現,所以如果緩衝區重疊,它可能最終複製已經複製的數據。
This幾乎可以解答你的問題。
它基本上告訴編譯器,只有這個指針或從它(指針+ 1)派生的指針才能訪問指針指向的內容。
您是否檢查[this](http://en.wikipedia.org/wiki/Restrict)? – 2012-02-02 17:31:43