Anonymous code blocks in c

What is a statement like this?

int x = ( { int a; scanf( "%d", &a ); a ; } ) ; 

It compiles and executes the equivalent:

 int x; scanf( "%d", &x ); 

It seems to be some kind of anonymous function call or something like that, but I'm not sure. I have not seen statements like ({}) before, and I cannot find any explanation on the Internet. Any help would be greatly appreciated, thanks :)

Context:

This is the code you get when the macros in the following code expand:

 #define SI ({int a;scanf("%d",&a);a;}); int x = SI; 

This is the code used by someone in a programming competition.

+4
source share
1 answer

This is an expression of expressions.
It is like a compiler extension supported by GCC, and it is not standard C ++, therefore, it is not portable.
If you compile your code with the -pedantic flag, this will tell you that.

This my answer tells in detail about it.

+6
source

All Articles