C关键字restrict的理解
来源:互联网 发布:linux禅道安装教程 编辑:程序博客网 时间:2024/04/30 11:01
void f (const int* pci, int *pi;); // is *pci immutable? { (*pi)+=1; // not necessarily: n is incremented by 1 *pi = (*pci) + 2; // n is incremented by 2 } int n; f( &n, &n);
In this example, both pci and pi point to the same variable, n. You can't change n's value through pci but you can change it using pi. Therefore, the compiler isn't allowed to optimize memory access for *pci by preloading n's value. In this example, the compiler indeed shouldn't preload n because its value changes three times during the execution of f(). However, there are situations in which a variable is accessed only through a single pointer. For example:
FILE *fopen(const char * filename, const char * mode);
The name of the file and its open mode are accessed through unique pointers in fopen(). Therefore, it's possible to preload the values to which the pointers are bound. Indeed, the C99 standard revised the prototype of the function fopen() to the following:
/* new declaration of fopen() in <stdio.h> */ FILE *fopen(const char * restrict filename, const char * restrict mode);
Similar changes were applied to the entire standard C library: printf(), strcpy() and many other functions now take restrict pointers:
int printf(const char * restrict format, ...); char *strcpy(char * restrict s1, const char * restrict s2);
C++ doesn't support restrict yet. However, since many C++ compilers are also C compilers, it's likely that this feature will be added to most C++ compilers too.
- C关键字restrict的理解
- c中restrict关键字的理解
- c语言中restrict关键字的理解
- C语言restrict关键字的使用
- C 语言 restrict 关键字的使用
- C 语言restrict 关键字的使用浅谈
- C 语言restrict 关键字的使用浅谈
- C 语言restrict 关键字的使用浅谈
- C 语言restrict 关键字
- C语言关键字 restrict
- C中restrict关键字
- C 语言restrict 关键字
- [C] 关键字restrict
- c中restrict关键字
- restrict 关键字的介绍
- C语言中restrict关键字
- C语言关键字 restrict 分析
- C/C++ 之 restrict关键字
- OGRE资源相关分析
- 关于windows消息
- SQL SERVER 表提示说明
- Ogre 材质
- VC入门笔记(四)
- C关键字restrict的理解
- MaterialSystem分析
- CodeSmith将模板文件批量生成文件的方法 - 空空如也 - 博客园
- Ogre中实现换装系统
- java运行时多态,后期绑定的初始化顺序
- Java.StringBuffer-StringBuilder
- 在64位服务器上安装oracle 32位客户端只能被编译为x86的程序连接
- VS2010中的各类文件作用[.sln,.suo,.vcxproj,.vcxproj.filters,.vcxproj.user]
- android编译系统学习总结