代码之家  ›  专栏  ›  技术社区  ›  Chiel

在某些C++编译器上使用限制限定符时出现编译器错误

  •  3
  • Chiel  · 技术社区  · 10 年前

    我有一个函数,它的指针为 double 作为限定为 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;
    
        // ...
    

    此代码使用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.
    

    我不知道如何解释这个错误,因为我没有更改变量的签名,也不知道我是否引入了未定义的行为或IBMBlueGene编译器是否错误。

    1 回复  |  直到 10 年前
        1
  •  6
  •   Leandros    10 年前

    IBM的XL C/C++编译器不支持您的构造 documentation 。不能相互分配受限指针。您可以通过创建一个新的块范围和一组新的指针来解决这个问题。

    {
      int * restrict  x;
      int * restrict  y;
      x = y; /* undefined */
      {
         int * restrict  x1 = x; /* okay */
         int * restrict  y1 = y; /* okay */
         x = y1;  /* undefined */
      }
    }