C++中restrict修饰符作用
2016-03-19 15:45
316 查看
今天查看POSIX的API时候,发现里面有一行
限制,限定; 约束,束缚
最后查询资料方得知:
restrict的定义是It can be applied only to pointers, and it indicates that a pointer is the sole initial means of
accessing a data object.
restrict是一个限定符,这个关键字据说来源于古老的FORTRAN,主要用来修饰指针指向的内存不能被别的指针引用。
restrict同样可以用于数组的声明:
If you specify type qualifiers such as void foo(int * restrict a);, the C compiler expresses it with array syntax void foo(int a[restrict]); which is essentially the same as declaring a restricted pointer.
其实restrict同const或valiate一样是一个修饰符而已,告诉编译器被restrict修饰的指针所指 向的对象,只能通过这个指针或基于这个指针的其他指针进行操作,即限制访问用restrict限制的指针指向的对象只能通过这个指针访问,这对编译器的优 化很有好处。
int pthread_create(pthread_t * restrict thread,const pthread_attr_t *restrictattr,void *(*start_routine)(void*),void*restrict arg);开始和不解为什么变量前面要加上restrict修饰符呢?restrict是
限制,限定; 约束,束缚
最后查询资料方得知:
restrict的定义是It can be applied only to pointers, and it indicates that a pointer is the sole initial means of
accessing a data object.
restrict是一个限定符,这个关键字据说来源于古老的FORTRAN,主要用来修饰指针指向的内存不能被别的指针引用。
restrict同样可以用于数组的声明:
If you specify type qualifiers such as void foo(int * restrict a);, the C compiler expresses it with array syntax void foo(int a[restrict]); which is essentially the same as declaring a restricted pointer.
其实restrict同const或valiate一样是一个修饰符而已,告诉编译器被restrict修饰的指针所指 向的对象,只能通过这个指针或基于这个指针的其他指针进行操作,即限制访问用restrict限制的指针指向的对象只能通过这个指针访问,这对编译器的优 化很有好处。
相关文章推荐
- const分别在C和C++语言里的含义和实现机制
- c语言中的“/”和“%”运算
- C++服务器(四):git 如何强制覆盖本地文件and socket 的异步模式
- 一个简单的Makefile
- c语言入门第一天
- 单例模式之C++实现
- 浅谈C++内存管理
- 第六届蓝桥杯省赛(c++)B组 移动距离;
- C++内存管理
- 程序设计第三次作业---C++计算器雏形
- 《C语言程序设计》指针篇<二>
- 《C语言程序设计》指针篇<一>
- 《算法竞赛入门经典》刘汝佳 C语言部分(前四章)“注解与习题” 之思索 <1>
- [C++] Strategy Pattern 实作
- 胡谈编程语言:从C语言到Julia
- usaco 2.1.4 holstein
- 软件工程课程作业(三)--四则运算3(C++)
- 指针与数组不同的存储区域
- 20160224.CCPP体系详解(0034天)
- 20160223.CCPP体系详解(0033天)