title: Returning struct * stored in fifo queue as void * (returning it by several functions)
body: <p>Hello I have a little problem with void * used to make code more generic. 
  I have written fifo queue (using linked list underneath) that is storing any data that can be casted to void * (i.e. struct * as void *). </p>
  
  <p>Now I have function that retrieves this data back. But the problem is that struct that has 3 fields is returned with only first field filled and others 2 are empty (was filled when placed in the queue).</p>
  
  <p>All functions like back(), unwrap'_data_from_node'() and fifo_dequeue() returns this data as void *.  What is more odd is that void * can be casted to struct * in fifo_dequeue() and it will contain all fields filled with data, while when returned from fifo_dequeue() the same pointer returned has only one field filled (1st field), and two are empty, nil. </p>
  
  <pre><code>   void *fifo_dequeue(fifo_queue_t *fifo, size_t *data_size) {
  
      doubly_linked_node_t *node;
      size_t tmp_size;
      void *tmp_data;
      void *data;
  
      // get data and its size from the last node in the queue
      if((node = back(fifo-&gt;queue)) == NULL) {
          fprintf(stderr, "back: queue is empty!\n");
          data_size = NULL;
          return NULL;
      };
      tmp_data = unwrap_data(node, &amp;tmp_size);
  
      /** HERE I tested casting data to struct test_t and it works properly **/
      task_t *task;
      task = (task_t *) tmp_data;
      int task_size = sizeof(task);
  
      // copy retrieved data
      data = malloc(tmp_size);
      memcpy(data, tmp_data, tmp_size);
  
      // remove the last node in the queue
      //pop_back(fifo-&gt;queue);
  
      if(data_size != NULL) *data_size = tmp_size; // return size of data through pointer argument
      return data; /** OUTSIDE this pointer casted to struct task_t has empty fields **/
  }
  </code></pre>
  
  <p>The underlying method removing node from linked list while making pop_back(); </p>
  
  <pre><code>   void remove_node(doubly_linked_list_t *list, doubly_linked_node_t *old_node) {
  
      // if node to delete unspecified return error
      if (old_node == NULL) {
          fprintf(stderr, "Node to delete is empty!");
          return;
      }
  
      // if node to delete is the only left on the list make empty list
      if (old_node-&gt;next == old_node) // or old_node-&gt;prev = old_node
      {
          list-&gt;head = list-&gt;tail = NULL;
      } else {
          old_node-&gt;prev-&gt;next = old_node-&gt;next;
          old_node-&gt;next-&gt;prev = old_node-&gt;prev;
  
          if(old_node == list-&gt;head) list-&gt;head = old_node-&gt;next;
          if(old_node == list-&gt;tail) list-&gt;tail = old_node-&gt;prev;
      }
  
      free(old_node-&gt;data); old_node-&gt;data = NULL;
      free(old_node); old_node = NULL;
  }
  </code></pre>