在我编写的程序中,我的一个函数声明是这样的:
bool parse( const sentence & __restrict sentence )
{
// whatever
}
当我使用 Microsoft Visual Studio 2010 Express 编译代码时,编译器报错:
warning C4227: anachronism used : qualifiers on reference are ignored
然而,this page GCC 的文档说:
In addition to allowing restricted pointers, you can specify restricted references, which indicate that the reference is not aliased in the local context.
同一个页面给出了一个非常明确的例子:
void fn (int *__restrict__ rptr, int &__restrict__ rref)
{
/* ... */
}
我是否误解了 MVSC 的警告?或者我应该将所有引用转换为指针以便应用 __restrict
吗?
最佳答案
C++ 没有像 C99 那样的 restrict
概念。
但是,一些编译器供应商为其 C++ 编译器提供扩展,他们称之为 __restrict
(注意保留名称!)。鉴于这些是扩展,它们的行为由编译器供应商决定。您必须阅读文档并分别了解此扩展在每个编译器中的作用。
仅仅因为两个供应商选择了相同的名称并不意味着扩展有任何共同点。
关于c++ - 我应该对引用使用 __restrict 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12841279/