Leonard

In theory, there is no difference between theory and practice. But, in practice, there is.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

C99中新增加了restrict修饰的指针:由restrict修饰的指针是最初唯一对指针所指向的对象进行存取的方法,仅当第二个指针基于第一个时,才能对对象进行存取。对对象的存取都限定于基于由restrict修饰的指针表达式中。 

由restrict修饰的指针主要用于函数形参,或指向由malloc()分配的内存空间。restrict数据类型不改变程序的语义。编译器能通过作出restrict修饰的指针是存取对象的唯一方法的假设,更好地优化某些类型的例程。 

[典型例子]

memcpy()在C99中,restrict可明确用于memcpy()的原型,而在C89中必须进行解释。

void *memcpy(void *restrict str1, const void *restrict str2, size_t size);

/*通过使用restrict修饰str1和str2来保证它们指向不重叠的对象*/ 

posted on 2011-10-06 09:21  Leonard Tse  阅读(6729)  评论(0编辑  收藏  举报