2

Let's consider the following piece of code:

#include <stdio.h>
int main() {
    int err = 
    (
        { 
            int _err = 0;
            for (int i = 0; i < 100; ++i) {
                _err += i;
            }
            _err;
        }
    );
    printf("%d", err);
}

I have found it (or well, a more complex incarnation of it) in the gcc testsuite and I became baffled by the construct:

int outer_var = ( { int local_var = 0; /* do some work on local_var */ local_var; } );

If I remove the braces (or the ; after the ) ), it fails to compile, but with braces on it compiles as c or even c++. What it does is more or less clear to me (although I have to admit, this is the very first time that I see a single variable in a standalone statement (_err;) which actually has a meaning) but I just haven't seen this construct till now, so I'd like to ask if there is an official name for it in any of the C or C++ standards.

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167

0 Answers0