28

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:

This compiler seems not to support this (i'm unsure):

  • MS Visual C++

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)

Daniel Kamil Kozar
  • 18,476
  • 5
  • 50
  • 64
osgx
  • 90,338
  • 53
  • 357
  • 513

3 Answers3

2

The PathScale® EKOPath Compiler Suite

It support gnu99 with "−std=gnu99"

plan9assembler
  • 2,862
  • 1
  • 24
  • 13
1

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

lrineau
  • 6,036
  • 3
  • 34
  • 47
  • 1
    But [the page](http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/cpp/lin/bldaps_cls/common/bldaps_gcc_compat_comm.htm) says "*Statement expressions are supported, except the following are prohibited inside them:*".. and [this, page4](http://scc.ustc.edu.cn/zlsc/lenovo_1800/200910/W020100308600680463493.pdf) says it is true since Intel C++ Compiler version 6.0 – osgx Jan 09 '13 at 07:42
1

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/

osgx
  • 90,338
  • 53
  • 357
  • 513
lrineau
  • 6,036
  • 3
  • 34
  • 47