我有一个函数,它的指针为doubleas 参数,被限定为restrict. 请注意,英特尔编译器使用restrict,但__restrict__在 GCC 的情况下,我们将限定符替换为。
void Stats::calc_flux_2nd(double* restrict data,
double* restrict datamean,
double* restrict w)
{
// ...
// Set a pointer to the field that contains w,
// either interpolated or the original
double* restrict calcw = w;
// ...
Run Code Online (Sandbox Code Playgroud)
使用 GCC 或 Clang 编译此代码没有任何问题,但 IBM BlueGene 编译器给出以下错误:
(W) Incorrect assignment of a restrict qualified pointer.
Only outer-to-inner scope assignments between restrict pointers are
allowed. This may result in incorrect program behavior.
Run Code Online (Sandbox Code Playgroud)
我不明白如何解释这个错误,因为我没有更改变量的签名,也不知道我是否引入了未定义的行为,或者 IBM BlueGene 编译器是否有问题。
IBM 的 XL C/C++ 编译器不支持您的构造,它们的文档中也说明了这一点。您不能相互分配受限制的指针。您可以通过创建一个新的块作用域和一组新的指针来解决这个问题。
{
int * restrict x;
int * restrict y;
x = y; /* undefined */
{
int * restrict x1 = x; /* okay */
int * restrict y1 = y; /* okay */
x = y1; /* undefined */
}
}
Run Code Online (Sandbox Code Playgroud)