0

I've found that you could in C++ do something like this:

int a = ({
    int x = 12 + 3;
    x*x + 7;
});

or like this:

bool x[] = {false, true, true, true, false};
if (({bool b = false; for (int i; i < 5; i++) if (x[i]) b = !b; b;}))
    printf("aaaaaaa\n");

Then I've found that I cannot do something like this:

int a = ({if (2 > 1) return x; x*x;});

nor

int a = ({if (2 > 1) x; x*x;});

nor

int a = ({x; if (1 > 2) printf("aaaa\n");});

What it is? Since when it is allowed? And how can I return result before closing bracket?

Dekakaruk
  • 661
  • 1
  • 8
  • 13

2 Answers2

1

This is a language extension. See Statement Exprs. Don't use it.

0

That's a language extension, it's not standard C++.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331