编译器支持GNU语句表达式

哪些现代编译器支持Gnu语句表达式(C和C ++语言)。 我应该使用哪个版本的语句表达式?

语句表达式就像({ code; code; retval })

 int b=56; int c= ({int a; a=sin(b); a}) 

我已经知道一些这样的编译器:

  • GCC> = 3
  • Clang / LLVM> =?
  • 英特尔C ++编译器> = 6.0(Linux版本, 检查第4页 ;位受限 )
  • Sun Studio> = 12( 新语言扩展 )
  • IBM XL for z / OS( 标记为IBM扩展 )
  • Open64(因为它使用了osprey-gcc前端)

这个编译器似乎不支持这个(我不确定):

  • MS Visual C ++

PS。 这里列出了一些C / C ++编译器,但我只对成熟编译器感兴趣,这些编译器被广泛使用(例如,不是tcc或turbo c)

PathScale®EKOPath编译器套件

它支持gnu99“ -std = gnu99 ”

英特尔C ++编译器不支持语句表达式,即使是我所知的最新版本,版本13.0。

正如我之前的回答评论所述,英特尔编译器确实支持语句表达式。 但英特尔在C ++中对GNU扩展的仿真并不完整。 以下代码取自CGAL-4.0(http://www.cgal.org/):

 #include  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; } 

代码中的注释甚至会给出英特尔编译器返回的错误,并使用版本11,12或13进行测试。

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