Compiler support of GNU Statement Expression

后端 未结 3 1598
别跟我提以往
别跟我提以往 2020-12-03 21:00

Which modern compilers support the Gnu Statement expression (C and C++ languages). What versions should I have to use a statement expressions?

Statement expression i

相关标签:
3条回答
  • 2020-12-03 21:12

    As said in the comment of my previous answer, the Intel Compiler does support the statement expressions. But the emulation by Intel of that GNU extension is not complete, in C++. The following code is taken from CGAL-4.0 (http://www.cgal.org/):

    #include <cassert>
    
    struct A {
      int* p;
    
      A(int i) : p(new int(i)) {}
      ~A() { delete p; }
      int value() const { return *p;}
    };
    
    int main()
    {
      int i = __extension__ ({ int j = 2; j+j; });
      assert(i == 4);
    
      // The Intel Compiler complains with the following error:
      // "error: destructible entities are not allowed inside of a statement
      // expression"
      // See http://software.intel.com/en-us/articles/cdiag1487/
      i = __extension__ ({ A a(2); A b(3); a.value() + b.value(); });
    
      assert(i == 5);
      return 0;
    }
    

    A comment in the code even give the error returned by the Intel Compiler, tested with version 11, 12, or 13.

    http://software.intel.com/en-us/articles/cdiag1487/

    0 讨论(0)
  • 2020-12-03 21:14

    The Intel C++ Compiler does not support statement expressions, even the last version that I know, version 13.0.

    0 讨论(0)
  • 2020-12-03 21:25

    The PathScale® EKOPath Compiler Suite

    It support gnu99 with "−std=gnu99"

    0 讨论(0)
提交回复
热议问题