2017-05-08 76 views
0

我們是否需要在方法的聲明和定義中使用restrict關鍵字,還是僅僅在C++代碼中的聲明文件中使用它就足夠了?什麼是正確的使用方法?在頭文件和源文件中限制使用

代碼編譯即使沒有限制在聲明中的用法。

例如

Foo.h 
class Foo 
{ 
    public: 
    void Bar(int* __restrict__ in, int* __restrict__ out); 
} 


Foo.cpp 

void Foo::Bar(int* __restrict__ in, int* __restrict__ out) 
{ 
} 
+3

[**「正如所有最參數預選賽,'__restrict__'在函數定義匹配忽略不計。這意味着你只需要在函數定義中指定'__restrict__',而不是在函數原型中。「**](https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html) – StoryTeller

回答

0

從接受答案@StoryTeller

As with all outermost parameter qualifiers, __restrict__ is ignored in 
function definition matching. This means you only need to specify __restrict__ in 
a function definition, rather than in a function prototype as well." – StoryTeller 
May 8 at 10:25 
相關問題