title: Wrapper around a Library
body: <p>Building on an answer from this <a href="https://stackoverflow.com/questions/4396140/why-doesnt-ansi-c-have-namespaces">question</a>.</p>
  <pre><code>/* interface.h */
  
  struct library {
      const int some_value;
      void (*method1)(void);
      void (*method2)(int);
      /* ... */
  };
  
  extern const struct library Library;
  /* interface.h */
  
  /* interface.c */
  #include &quot;interface.h&quot;
  
  void method1(void)
  {
     ...
  }
  void method2(int arg)
  {
     ...
  }
  
  const struct library Library = {
      .method1 = method1,
      .method2 = method2,
      .some_value = 36
  };
  /* end interface.c */
  
  /* client code */
  #include &quot;interface.h&quot;
  
  int main(void)
  {
      Library.method1();
      Library.method2(5);
      printf(&quot;%d\n&quot;, Library.some_value);
      return 0;
  }
  /* end */
  </code></pre>
  <p>How can I put a wrapper around Library?</p>
  <p>Wrapper.h</p>
  <pre><code>struct Wrapper {
     const Library
  };
  
  extern const struct wrapper Wrapper;
  </code></pre>
  <p>Wrapper.c</p>
  <pre><code>const struct wrapper Wrapper = {
      .Library = Library
  };
  </code></pre>
  <p>and then access like <code>wrapper.Library.method1();</code></p>