Which modern compilers support the Gnu Statement expression (C and C++ languages). What versions should I have to use a statement expressions?
Statement expression is smth like ({ code; code; retval })
:
int b=56;
int c= ({int a; a=sin(b); a})
I already know some such compilers:
- GCC >=3
- Clang/LLVM >= ?
- Intel C++ Compiler >= 6.0 (Linux version, check page 4; bit limited)
- Sun Studio >= 12 (New Language Extensions)
- IBM XL for z/OS (marked as IBM extension)
- Open64 (as it uses osprey-gcc frontend)
This compiler seems not to support this (i'm unsure):
PS. some C/C++ compilers are listed here but I interested only in mature compilers, that are used widely (e.g not a tcc or turbo c)
The PathScale® EKOPath Compiler Suite
It support gnu99 with "−std=gnu99"
The Intel C++ Compiler does not support statement expressions, even the last version that I know, version 13.0.
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/