2011-06-22 27 views
20

哪些现代编译器支持Gnu语句表达式(C和C++语言)。我需要使用什么版本的语句表达式?编译器对GNU语句表达式的支持

声明表达是不便等({ code; code; retval })

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

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

这个编译器好像不支持这样(我不确定):

  • MS Visual C++

PS。一些C/C++编译器中列出here但我感兴趣的只是成熟的编译器,被广泛使用(例如不是TCC或涡轮C)

回答

1

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

+1

但[页](http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/cpp/lin/bldaps_cls/ common/bldaps_gcc_compat_comm.htm)表示“*语句表达式被支持,除了以下内容被禁止:*”..和[this,page4](http://scc.ustc.edu.cn/zlsc/lenovo_1800/200910 /W020100308600680463493.pdf)说这是真正的sinc e英特尔C++编译器6.0版 – osgx

+0

您是对的。我会做出更好的回答。 – lrineau

0

正如我以前回答的评论所说,英特尔编译器确实支持语句表达式。但是,英特尔对该GNU扩展的仿真在C++中并不完整。

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

在代码中的注释甚至给由英特尔编译器返回的错误,与11版进行测试,12:下面的代码是从CGAL-4.0(http://www.cgal.org/)拍摄,或13

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