about qualifier "restrict"
来源:互联网 发布:pc3000数据恢复 编辑:程序博客网 时间:2024/06/03 20:40
about qualifier "restrict":
One of the new features in the recently approved C standard C99, is the restrict pointer qualifier. This qualifier can be applied to a data pointer to indicate that, during the scope of that pointer declaration, all data accessed through it will be accessed only through that pointer but not through any other pointer. The 'restrict' keyword thus enables the compiler to perform certain optimizations based on the premise that a given object cannot be changed through another pointer. Now you're probably asking yourself, "doesn't const already guarantee that?" No, it doesn't. The qualifier const ensures that a variable cannot be changed through a particular pointer. However, it's still possible to change the variable through a different pointer. For example:
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);
pci和pi指向的都是n,虽然pci被const修饰,但pci指向的内容却在函数中被改变了,当用restrict修饰符之后 void f ( const int * restrict pci , int * restrict pi ),问题解决了:一旦我们再有如:f ( &n , &n ) 的调用,编译器将给出错误提示,这是由于一个地址可以通过两个指针来访问
Note: The qualifier "restrict" isn't support by C89 or C++, If can't conpliar, please add "-std = C99"
- about qualifier "restrict"
- How to Use the restrict Qualifier in C
- @Qualifier
- restrict
- restrict
- restrict
- restrict
- restrict
- restrict
- restrict
- restrict
- restrict
- Spring @Qualifier
- @Qualifier example
- CV-qualifier
- @Qualifier注解
- @Qualifier注解
- Spring @Qualifier
- hibernate映射oracle数据表时候出现“ORA-00903: 表名无效”问题
- Oracle笔记 三、function 、select
- 如何抓取QQ2010的聊天框
- 能不能通过API导出和导入快捷键的配置文件
- 做锚文本链接需要注意哪些事项
- about qualifier "restrict"
- C/C++读写文件小结
- 静态数据成员和静态成员函数
- 字符集和字符编码(Charset & Encoding)
- 这是我选择的路
- iPhone Objective-C EXC_BAD_ACCESS问题
- 2012版Workset的新功能
- C#内存分配
- tomcat5.X 配置手册