title: Global Variable within Multiple Files
body: <p>I have two source files that need to access a common variable. What is the best way to do this? e.g.:</p>
  
  <p>source1.cpp:</p>
  
  <pre><code>int global;
  
  int function();
  
  int main()
  {
      global=42;
      function();
      return 0;
  }
  </code></pre>
  
  <p>source2.cpp:</p>
  
  <pre><code>int function()
  {
      if(global==42)
          return 42;
      return 0;
  }
  </code></pre>
  
  <p>Should the declaration of the variable global be static, extern, or should it be in a header file included by both files, etc?</p>