开发者

restrict qualifier and pointer arithmetic

开发者 https://www.devze.com 2023-03-07 08:27 出处:网络
Does incrementing or decrementing a restrict qualified pointer preserve no aliasing assumption? // a and b point to disjoint arrays

Does incrementing or decrementing a restrict qualified pointer preserve no aliasing assumption?

// a and b point to disjoint arrays
void foo(size_t n, double * __restrict a, double * __restrict b) {
    size_t 开发者_运维百科i;
    double x, y, z;
    double * c = b; // copy
    for(i=0; i<n; ++i) {
        x = *(a++);     // not aliased
        y = *(b + i);   // not aliased 
        z = c[i];       // not aliased
    }
}

Thank you.


Yes. The restrict qualifier is part of the type of the pointer, and this type isn't changed when you increment, decrement, or assign it.

0

精彩评论

暂无评论...
验证码 换一张
取 消