c++ - 我应该对引用使用 __restrict 吗?

标签 c++ visual-c++ gcc reference restrict-qualifier

在我编写的程序中,我的一个函数声明是这样的:

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/

相关文章:

c++ - 如何在 Mac 上使用 c++2a 编译生成器和协程

将 SDL_ttf 与 SDL 和 SDL2 一起使用时出现 C++ 访问冲突

gcc - 编译 GCC 5.3.0 时出现编译器错误(-Lyes/lib 和 -Iyes/include)

c++ - 向此正则表达式添加最少字符

c++ - 将Rcpp数值 vector 转换为boost:ublas:vector

c++ - CLSID_WICPngDecoder 上的 REGDB_E_CLASSNOTREG

c++ - PPL 任务中 .then 构造的目的是什么?

c++ - Qt cross-platform issue : compiles fine on Windows, linker error on Linux

iphone - 在 Xcode 中设置 GCC 4.2.1 选项

c++ - 从可执行文件中读取和验证证书