title: Theory: getter/setter function or global variable? C
body: <p>I'm currently writing a C <strong>LIBRABY</strong> where I need to use a static void*.</p>
  
  <p>In my first version I was putting all my functions that need to access my void* in the same C file it was declared in, like this:</p>
  
  <p>main.c</p>
  
  <pre><code>int main()
  {
    function_using_list();
  }
  </code></pre>
  
  <p>foo.c:</p>
  
  <pre><code>void *list=NULL;
  
  void *function_using_list()
  {
    //stuff with list
  }
  </code></pre>
  
  <p>In my second version I made a little get/set function so I can access my list through it from anywhere in my code:</p>
  
  <p>foo.c</p>
  
  <pre><code>void   *getset_list(void nlist, int action)
  {
     static void  *list = NULL;
  
     if (action == 1)
       return (list)
     else
       list = nlist;
  }
  </code></pre>
  
  <p>What are the pros and cons of these two different designs? Is the second one Thread-safe?</p>
  
  <p><strong>PS:</strong> I just realized that I forgot something in my question: This code is meant to be used as a library.</p>