title: How do I use Opaque Pointers in C?
body: <p>I'm going through the C book online, I don't understand 6.6 on struct pointers. I'm trying to return a pointer to a doubly linked list in an initialize function and have lost my way.</p>
  
  <p>.h has an opaque pointer to reference doubly linked list(s):</p>
  
  <pre><code>typedef void * d_link_list_t;
  </code></pre>
  
  <p>.c implementation has the list struct definition:</p>
  
  <pre><code>    typedef struct list_s
      {
          node_t * head;
          node_t * tail;
          int count; //num nodes
      } list_t
  </code></pre>
  
  <p>.c later I have the implementation of the initialize function where problem is:</p>
  
  <pre><code>d_link_list_t* Initialize(void)
  {
       //Converting opaque pointer to real pointer
        d_link_list_t* list = (d_link_list_t*)malloc(sizeof(d_link_list_t*));
  
  
  
       // Now make concrete list_t pointer and set the members
        list_t  * rlP;//real list pointer
        rlP = (list_t*)malloc(sizeof(list_t));
        rlP-&gt;head = NULL;
       rlP-&gt;tail = NULL;
       rlP-&gt;count = 1;
  
       //cast opaque pointer to real list P PROBLEM HERE
       list = (d_link_list_t*)rlP;
        list-&gt;count = 0; //list IS NOT STRUCT
  
        return list;
  }
  </code></pre>
  
  <p>I want to return <code>* d_link_list_t</code> , an opaque pointer that will reference an instance of a linked list. I want all my functions in the implementation.c to use the list that this opaque pointer in the .h references.  I don't understand how to do that at all. </p>
  
  <p>I tried just casting the opaque pointer to the list_t struct pointer - expecting the opaque pointer to point to the same place as the struct pointer but this seems wrong. Trying to access count with '->' gives the error "Trying to access member 'count' in something not a struct or union"</p>
  
  <p>How can I make the void Opaque pointer reference my list_t struct? Please help me!</p>