那位朋友知道__restrict__关键字的作用是干什么?

IUnknown9989 2005-05-22 04:42:55
那位朋友知道__restrict__关键字的作用是干什么?

谢谢!
下面是google的结果---我没有看明白:
As with the C front end, G++ understands the C99 feature of restricted pointers, specified with the __restrict__, or __restrict type qualifier. Because you cannot compile C++ by specifying the -std=c99 language flag, restrict is not a keyword in C++.

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)
{
/* ... */
}

In the body of fn, rptr points to an unaliased integer and rref refers to a (different) unaliased integer.

You may also specify whether a member function's this pointer is unaliased by using __restrict__ as a member function qualifier.

void T::fn () __restrict__
{
/* ... */
}

Within the body of T::fn, this will have the effective definition T *__restrict__ const this. Notice that the interpretation of a __restrict__ member function qualifier is different to that of const or volatile qualifier, in that it is applied to the pointer rather than the object. This is consistent with other compilers which implement restricted pointers.

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
...全文
436 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zsal 2005-05-23
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/21/21390.shtm
看看这个,也许对你有所帮助。
IUnknown9989 2005-05-23
  • 打赏
  • 举报
回复
"restrict 是c99的一个关键字"

请问这个restrict关键字有什么用?
谢谢
step_by_step 2005-05-23
  • 打赏
  • 举报
回复
简单的意思就是说:

restrict 是c99的一个关键字,而不是c++的关键字,为了在g++中使用这个特性,g++自己进行了内部扩充引入了__restrict__这个关键字。

good luck
  • 打赏
  • 举报
回复
应该就是C99的 restrict 啦, gcc 把它扩展到鸟 C++ 中。
liujingfu123 2005-05-23
  • 打赏
  • 举报
回复
我也不知道啊,学习先
qfeng_zhao 2005-05-23
  • 打赏
  • 举报
回复
不明白,帮忙顶一下
zsal 2005-05-23
  • 打赏
  • 举报
回复
Fortran编译程序允许做出这样的假定:如果传递给函数两个数组参数,那么这两个数组相互是没有重叠的。对于C++就不能这样假定。由这个假定Fortran子程序得到15%到30倍的加速,具体情况依赖于编译程序和计算机体系结构。在这里令人吃惊的速度提升来自于具有特殊硬件机器上的向量化运算,如Cray机器。
C语言是强调效率的,这种情况被认为是一种侮辱,对此ANSI C委员会提出过一种称为noalias的机制来解决这个问题,用它来说明某个C指针可以认为是没有别名的。不幸的是这个建议来晚了,而且又是如此的不成熟。这件事激怒了Dennis Ritchie,拿他对C的标准化过程做了唯一的一次干预。他写了一封公开信说“noalias必须靠边站,这一点是不能协商的。”
后来Cray的Mike Holly又抓起了这个难题,向数值C语言扩充工作组和C++委员会提出了一种改进的反别名建议。所建议的想法是允许程序员说明一个指针可以认为是没有别名的,采用的方式是将它说明为restrict。
这个建议C99采纳了,但标准C++拒绝了。在C++中将依赖编译器来兼容C99,这也就是楼主查到的那一段说明。
ltc_mouse 2005-05-23
  • 打赏
  • 举报
回复
学习~
IUnknown9989 2005-05-22
  • 打赏
  • 举报
回复
分隔函数?

什么意思?
xuzheng318 2005-05-22
  • 打赏
  • 举报
回复
/* Divide S into tokens separated by characters in DELIM. Information
passed between calls are stored in SAVE_PTR. */
extern char *__strtok_r (char *__restrict __s,
__const char *__restrict __delim,
char **__restrict __save_ptr) __THROW;
#if defined __USE_POSIX || defined __USE_MISC
extern char *strtok_r (char *__restrict __s, __const char *__restrict __delim,
char **__restrict __save_ptr) __THROW;
分隔函数

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧