I found strange macros in a driver implementation that I can't explain to myself. Simplified example is:
cout << ({int i=0; while(i<10) {++i;} i;}) << endl;
It will output 10.
But why this does expression become an rvalue at all? It seems to work in C and in C++.
Can someone explain me? Pointing to keywords and to reference will be great.
The is a GCC extension:
A compound statement enclosed in parentheses may appear as an expression in GNU C.
The last thing in the compound statement should be an expression followed by a semicolon; the value of this subexpression serves as the value of the entire construct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With