3

I wonder what kind of expression is ({ .. statements .. }) in C?

For example:

#include <stdio.h>

int main() {
    int x = ({
            const int i = 10;
            i*2;
    });
    printf("Result: %d\n", x);
    return 0;
}

The above code returns 20. So it seems like the statements in ({ .. }) are executed and the result of the last statement returned? What type of construction is it? Where do I read more about it?

Soid
  • 2,585
  • 1
  • 30
  • 42
  • 1
    I find it amazing that you still have to pay to get the C language standard documents. – jarmod Jan 26 '20 at 16:32
  • 1
    @jarmod -- there is a hyperlinked copy of the [C11 Draft Standard](http://port70.net/~nsz/c/c11/n1570.html) available online. There is also [this SO question](https://stackoverflow.com/questions/81656/where-do-i-find-the-current-c-or-c-standard-documents) with several sources for pdfs. But the Standard does not provide answers to questions about compiler-specific features such as this. – ad absurdum Jan 26 '20 at 16:39
  • @exnihilo thanks, that's helpful, particularly that this is not standard C, but a gcc extension. – jarmod Jan 26 '20 at 16:43

0 Answers0