Search code examples
c++extern

Why does value assignment exclude extern keyword and declare variable?


I understand why this won't link:

extern bool g_WinGame;
...
g_WinGame=true;

But why does this compile and link?

extern bool g_WinGame=false;
...
g_WinGame=true;

I'm using MSVC 2010

[edit] all is explained HERE


Solution

  • extern bool g_WinGame;
    

    is a declaration.

    extern bool g_WinGame=false;
    

    is a definition. Here extern is redundant but legal.