c - 结构中 restrict 关键字的行为

标签 c struct c99 restrict-qualifier

场景:

假设我有一个 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.ptrXXinput.ptrYY 将被视为无锯齿。

问题:

编译器是否会将 input.ptrXXoutput.ptrYY 也视为非别名?

最佳答案

应该。对于您在某处声明为 restrict 的每个指针,编译器可以假定它是对相应数据的唯一访问。通过声明这些,您实际上向编译器提供了保证。

是否所有编译器都会利用该信息是另一个问题。通过struct 传递restrict 指针不是很常见,所以您必须看看您的编译器做了什么。

关于c - 结构中 restrict 关键字的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28478312/

相关文章:

C 中整数到字符数组的转换

c++ - 分数结构数组

c - 了解 mmap 大小参数

c - 序列点和副作用 : Quiet change in C11?

c - 当我的所有输入都是整数时,为什么使用 float 而不是 int 会给出不同的结果?

c - 为什么 CHECK_FUNCTION_EXISTS 在 CMake 中找不到 clock_gettime?

c - 如何知道我从哪里启动

C从文本文件中读取结构

c - 交换动态分配的结构

c - 为什么这个 C 程序符合并运行