场景:
假设我有一个 struct
类型,其中包含一堆指针,所有这些都声明为 restrict
,还有一个函数接受其中的几个 struct
作为参数如下:
struct bunch_of_ptr
{
double *restrict ptr00;
double *restrict ptr01;
...
double *restrict ptr19;
}
void evaluate(struct bunch_of_ptr input, struct bunch_of_ptr output)
{
// do some calculation on input and return results into output
}
根据 http://www.oracle.com/technetwork/server-storage/solaris10/cc-restrict-139391.html , input.ptrXX
和 input.ptrYY
将被视为无锯齿。
问题:
编译器是否会将 input.ptrXX
和 output.ptrYY
也视为非别名?
最佳答案
应该。对于您在某处声明为 restrict
的每个指针,编译器可以假定它是对相应数据的唯一访问。通过声明这些,您实际上向编译器提供了保证。
是否所有编译器都会利用该信息是另一个问题。通过struct
传递restrict
指针不是很常见,所以您必须看看您的编译器做了什么。
关于c - 结构中 restrict 关键字的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28478312/