restrict关键字在C ++中的意思是什么? [英] What does the restrict keyword mean in C++?

查看:310
本文介绍了restrict关键字在C ++中的意思是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是不确定,restrict关键字在C ++中是什么意思?

I was always unsure, what does the restrict keyword mean in C++?

是否意味着给这个函数的两个或更多的指针不重叠?
还有什么意思?

Does it mean the two or more pointer given to the function does not overlap? What else does it mean?

推荐答案

在他的论文中,内存优化,Christer Ericson说,虽然 restrict 不是C ++标准的一部分,它由许多编译器支持,并建议在可用时使用:

In his paper, Memory Optimization, Christer Ericson says that while restrict is not part of the C++ standard yet, that it is supported by many compilers and he recommends it's usage when available:


限制关键字

restrict keyword

!新到1999年的ANSI / ISO C标准

! New to 1999 ANSI/ISO C standard

!不是在C ++标准中,但由许多C ++编译器支持

! Not in C++ standard yet, but supported by many C++ compilers

限制合格的指针(或引用)...

A restrict-qualified pointer (or reference)...

! ...基本上是一个
承诺的编译器,对于
范围的指针,目标的指针将只有
通过该指针访问(和指针复制
从它)。

! ...is basically a promise to the compiler that for the scope of the pointer, the target of the pointer will only be accessed through that pointer (and pointers copied from it).

在支持它的C ++编译器中,它应该可能与C中的一样。

In C++ compilers that support it it should probably behave the same as in C.

有关详情,请参阅此SO职位:现实用法C99'restrict'关键字?

See this SO post for details: Realistic usage of the C99 ‘restrict’ keyword?

花半个小时浏览埃里克森的论文,这很有趣,值得花时间。

Take half an hour to skim through Ericson's paper, it's interesting and worth the time.

编辑

我还发现IBM的 AIX C / C ++编译器支持 __ restrict __ 关键字

I also found that IBM's AIX C/C++ compiler supports the __restrict__ keyword.

g ++似乎也支持这一点,因为下面的程序在g ++上完全编译:

g++ also seems to support this as the following program compiles cleanly on g++:

#include <stdio.h>

int foo(int * __restrict__ a, int * __restrict__ b) {
    return *a + *b;
}

int main(void) {
    int a = 1, b = 1, c;

    c = foo(&a, &b);

    printf("c == %d\n", c);

    return 0;
}



我还发现了一个关于使用限制

了解限制关键字

Edit2

我遇到了一篇文章,具体讨论了在C ++程序中使用restrict:

I ran across an article which specifically discusses the use of restrict in C++ programs:

Load-hit-stores and the __restrict keyword

此外,Microsoft Visual C ++ 也支持 __ restrict 关键字

Also, Microsoft Visual C++ also supports the __restrict keyword.

这篇关于restrict关键字在C ++中的意思是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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