Is it valid to use extern in a local scope to unshadow a global variable?

  c++, extern, global-variables, local-variables

Is this extern declaration in a nested local scope a valid and defined way to bring the global a back into the scope?

int a = 1; // may be in another file
void main() {
    int a = 2; // hides the global
    {
        extern int a;
        cout << ::a << endl; // obviously 1
        cout << a << endl;  // also prints 1
    }
}

Source: Windows Questions C++

LEAVE A COMMENT