我应该使用__restrict引用吗? [英] Should I use __restrict on references?

查看:166
本文介绍了我应该使用__restrict引用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我编写的程序中,我的一个函数声明如下:

In the program I am coding, one of my function declarations goes like this:

bool parse( const sentence & __restrict sentence )
{
  // whatever
}

我编译代码与Microsoft Visual Studio 2010 Express,编译器抱怨:

When I compile the code with Microsoft Visual Studio 2010 Express, the compiler complains:


警告C4227:anachronism used: p>

warning C4227: anachronism used : qualifiers on reference are ignored

但是,这个页面的GCC文档说:

However, this page of GCC’s documentation says:


除了允许受限制的指针,这表示引用在本地上下文中没有别名。

In addition to allowing restricted pointers, you can specify restricted references, which indicate that the reference is not aliased in the local context.

同一页给出了一个非常明确的例子:

And the same page gives a very explicit example:

 void fn (int *__restrict__ rptr, int &__restrict__ rref)
 {
   /* ... */
 }

我误解了MVSC的警告吗?或者我应该将所有的引用转换为指针,以便 __ restrict 适用吗?

Did I misunderstand MVSC’s warning? or should I transform all my references into pointers so that __restrict applies?

推荐答案

C ++没有C99的方式 c>限制 c>的概念。

C++ has no notion of restrict in the way C99 does.

然而,几个编译器供应商提供扩展他们的C ++编译器,他们调用 __ restrict (注意保留名称!)。考虑到这些是扩展,它们的行为由com­ pi­ ler供应商决定。你必须阅读文档,并在每个com­ pi­ ler分别找到这个扩展。

However, several compiler vendors offer extensions to their C++ compilers, which they call __restrict (note the reserved name!). Given that those are extensions, their behaviour is determined by the com­pi­ler vendor. You will have to read the documentation and find out what this extension does in each com­pi­ler separately.

只是因为两个供应商选择相同的名称不意味着这些扩展具有共同点。

Just because two vendors chose the same name doesn't mean the extensions have anything in common.

这篇关于我应该使用__restrict引用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆