title: Should variable definition be in header files?
body: <p>
  My very basic knowledge of <strong>C</strong> and compilation process has gone rusty lately. I was trying to figure out answer to the following question but I could not connect compilation, link and pre-processing phase basics. A quick search on the Google did not help much either. So, I decided to come to the ultimate source of knowledge :)
  </p>
  
  <p><strong>I know:</strong> Variables should not be defined in the .h files. Its ok to declare them there.</p>
  
  <p><strong>Why:</strong> Because a header file might get included from multiple places, thus redefining the variable more than one time (Linker gives the error).</p>
  
  <p><strong>Possible work-around:</strong> Use header-guards in header files and define variable in that.</p>
  
  <p><strong>Is it really a solution:</strong> No. Because header-guards are for preprocessing phase. That is to tell compiler that this part has been already included and do not include it once again. But our multiple definition error comes in the linker part - much after the compilation.</p>
  
  <p>This whole thing has got me confused about how preprocessing &amp; linking work. I thought that preprocessing will just not include the code, if the header guard symbol has been defined. In that case, shouldn't multiple definition of a variable problem also get solved?</p>
  
  <p>What happens that these preprocessing directives save the compilation process from redefining symbols under header guards, but the linker still gets multiple definitions of the symbol?</p>