Why is this legal?
extern int foo = 0xF00; // Gets a warning, still compiles
extern void bar() { // No warning
int x;
}
Is there a reason to why this is allowed?
Sometimes it's useful
extern const int foo = 0xF00;
Without the extern
, in C++ foo
would be static
and have internal linkage (which means you could not use foo
from another translation unit).
The extern
in both cases in your example is redundant. In C99 an extern
can make a difference for inline
functions..
In the function case, I think it is just like writing:
extern void bar();
void bar()
{
int x;
}
which must be legal since a file with the definition may include a header with such a declaration.
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