I wrote the following code
#include<iostream>
using namespace std;
extern int var = 0;
int main(void)
{
var = 10;
return 0;
}
I used
g++ -std=c++11 test.cpp -o test
and
g++ test.cpp -o test
to compile the code. And I got the following warning
test.cpp:44:12: warning: 'extern' variable has an initializer [-Wextern-initializer]
extern int var = 0;
^
1 warning generated.
What does this mean? Do I need to worry about this? How can I avoid it? Thanks a lot~
extern int var = 0;is not just a declaration; it also defines the variablevar, because of the initializer. In this context, theexternis essentially noise.