title: When is it ok to use a global variable in C?
body: <p>Apparently there's a lot of variety in opinions out there, ranging from, &quot;<strong>Never!  Always encapsulate (even if it's with a mere macro!)</strong>&quot; to &quot;<strong>It's no big deal – use them when it's more convenient than not.</strong>&quot;</p>
  <p>So.</p>
  <p>Specific, concrete reasons (preferably with an example)</p>
  <ul>
  <li>Why global variables are dangerous</li>
  <li>When global variables <em>should</em> be used in place of alternatives</li>
  <li>What alternatives exist for those that are tempted to use global variables inappropriately</li>
  </ul>
  <p>While this is subjective, I will pick one answer (that to me best represents the love/hate relationship every developer should have with globals) and the community will vote theirs to just below.</p>
  <p>I believe it's important for newbies to have this sort of reference, but please don't clutter it up if another answer exists that's substantially similar to yours – add a comment or edit someone else's answer.</p>