title: Dereferencing pointer to incomplete type when providing function pointer
body: <p>I'm getting the dereferencing pointer to incomplete type error when I try to run the following code. I've checked several other questions about this error and from what I can tell it's not due to a missing or extra struct keyword and I believe the pointer type is correct but I could be mistaken.</p>
  
  <p>There might be other issues with the code as I'm just learning C, I'm happy to try and figure them out for myself I just can't seem to track down the issue with the incomplete type error. </p>
  
  <pre><code>Development/C/AI/test/src/test.c: In function ‘compare’:
  Development/C/AI/test/src/test.c:10:19: error: dereferencing pointer to incomplete type ‘lrgraph_node {aka struct lrgraph_node}’
    if ( strcmp(other-&gt;dataType, current-&gt;dataType == 0) ) {
  </code></pre>
  
  <p>test.c</p>
  
  <pre><code>#include "lrGraph.h"
  #include &lt;string.h&gt;
  
  int data = 1;
  char *dataType = "int";
  lrgraph_edge *connected[] = {};
  unsigned numEdges = 0;
  
  int compare( lrgraph_node *other, lrgraph_node *current ) {
      if ( strcmp(other-&gt;dataType, current-&gt;dataType == 0) ) {
          return (int)other-&gt;data - (int)current-&gt;data;
      }
      return -1;
  }
  
  int main() {
      lrgraph_node *nodeA = lrgraph_createNode((void*)&amp;data, dataType, &amp;compare, connected, numEdges);
      lrgraph_printVersion();
  }
  </code></pre>
  
  <p>lrGraph.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include "lrGraph.h"
  
  struct lrgraph_edge {
      float weight;
      lrgraph_node *nodeA;
      lrgraph_node *nodeB;
  };
  
  struct lrgraph_node {
      //data can be of any type
      void *data;
      //string to see if this node can be compared to another node based on data type
      char *dataType;
      int numEdges;
      //comparator function which compares another node to this node
      int (*compare)(lrgraph_node *other, lrgraph_node *current);
      //array of connected edges
      lrgraph_edge *connected[];
  };
  
  void lrgraph_printVersion() {
      fprintf(stdout, "\nlrgraph version 0.01b\n");
  }
  
  
  lrgraph_node* lrgraph_createNode(void *data, char *dataType, int (*compare)(lrgraph_node* other, lrgraph_node* current), lrgraph_edge *connected[], unsigned numEdges) {
      //allocate enough memory for the struct plus each pointer in the array of edges - https://stackoverflow.com/questions/32311269/can-we-have-a-struct-element-of-type-variable-length-array
      lrgraph_node *node = malloc(sizeof(lrgraph_node) + numEdges * sizeof(lrgraph_edge));
      if (NULL != node) {
          node-&gt;data = data;
          node-&gt;dataType = strdup(dataType);
          node-&gt;compare = compare;
          node-&gt;numEdges = numEdges;
          //initialize each edge in the array
          for( unsigned i=0; i &lt; numEdges; i++) {
              node-&gt;connected[i] = connected[i];
          }
      }
      return node;
  }
  </code></pre>
  
  <p>lrGraph.h</p>
  
  <pre><code>#ifndef LRGRAPH_H
  #define LRGRAPH_H
  
  typedef struct lrgraph_node lrgraph_node;
  
  typedef struct lrgraph_edge lrgraph_edge;
  
  lrgraph_node* lrgraph_createNode(void *data, char *dataType, int (*compare)(lrgraph_node *other, lrgraph_node *current), lrgraph_edge *connected[], unsigned numEdges);
  
  void lrgraph_printVersion();
  
  #endif /*LRGRAPH_H*/
  </code></pre>