Closed
Description
This C code:
static int x;
void f(void)
{
extern int x = 1;
}
leads to:
error: 'extern' variable cannot have an initializer
which is confusing, because extern
variable CAN have an initializer, which is demonstrated by the C standard (C11, 6.9.2 External object definitions, 4, EXAMPLE 1):
extern int i3 = 3; // definition, external linkage
The expected diagnostics is:
error: declaration of block scope identifier x with internal linkage shall have no initializer
Relevant quote from C11:
If the declaration of an identifier has block scope, and the identifier has external or internal linkage, the declaration shall have no initializer for the identifier.