title: Best way to abstract away an init function?
body: <p>I am making a low level library that requires initialization to work properly which I implemented with a init function. I am wondering if there is a way to make the init call be called once the user calls a library function ideally without:</p>
  <ol>
  <li>Any overhead</li>
  <li>No repeated calls</li>
  <li>No exposed global variables. (my current solution does this, which I don't quite like)</li>
  </ol>
  <p>my current solution as per comment request:</p>
  <pre class="lang-c prettyprint-override"><code>bool isinit = 0;
  
  void init()
  {
    isinit = 1;
    // init code
  }
  
  void lib_function()
  {
    if(!isinit) init();
    // function code
  }
  </code></pre>
  <p>The compiler seems to be smart enough (using -0fast on gcc) to not make that comparison each time a lib_function is called, but this still exposes a global variable which I don't like.</p>