pic11
pic11

Reputation: 14973

restrict qualifier and pointer arithmetic

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.

Upvotes: 2

Views: 400

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213608

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.

Upvotes: 3

Related Questions