1

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.

pic11
  • 14,267
  • 21
  • 83
  • 119
  • 1
    [mode pedantic] `restrict` is spelled without underscores in C99 since it is a language keyword. There is no such thing as `restrict` in the (any ?) C++ standard, although some implementations provide a replacement[/mode] – Alexandre C. May 22 '11 at 09:56
  • The __restrict qualifier is a not uncommon extension, supported in several C and C++ compilers. – Dietrich Epp May 22 '11 at 10:09

1 Answers1

3

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.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415