title: Incompatible pointer type warning C
body: <p>Thanks for your help in advance. I am trying to create a simple graph in C. I however get </p>
  
  <pre><code>graph.c:66:11: warning: incompatible pointer types initializing
        'edge *' (aka 'struct gegde *') with an expression of type
        'struct gedge *' [-Wincompatible-pointer-types]
      edge *node = fromptr-&gt;nextedge;
            ^      ~~~~~~~~~~~~~~~~~
  graph.c:69:14: warning: incompatible pointer types assigning to
        'edge *' (aka 'struct gegde *') from 'struct gedge *'
        [-Wincompatible-pointer-types]
          node = node-&gt;nextedge;
               ^ ~~~~~~~~~~~~~~
  graph.c:75:44: error: incomplete definition of type 'struct gedge'
      printf("val is %c\n", fromptr-&gt;nextedge-&gt;link-&gt;element);
                            ~~~~~~~~~~~~~~~~~^
  graph.c:7:12: note: forward declaration of 'struct gedge'
      struct gedge *nextedge;
             ^
  </code></pre>
  
  <p>Here is my code, I am not sure where I am going wrong. I don't understand why am I getting the incompatible warning and the forward declaration error.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stddef.h&gt; 
  #include "graph.h"
  
  typedef struct gegde {
      struct gedge *nextedge;
      struct gvertex *link;
  }edge;
  
  typedef struct gvertex {
      ge element;
      struct gvertex *nextvertex;
      struct gedge *nextedge;
      int visited;
  }vertex;
  
  void graph_add(ge c, vertex **root, vertex **last)
  {
      vertex *temp = *root;
      printf("root points to %p\n", *root);
      while (temp != NULL) {
          // vertex already exists in graph, ignore insert
          if (temp-&gt;element == c) {
              return;
          }
          temp = temp-&gt;nextvertex;
      }
  
      vertex *v = malloc(sizeof(*v));
      v-&gt;element = c;
      v-&gt;nextedge = NULL;
      // first vertex in graph
      if (*root == NULL) {
          *root = v;
          *last = *root;
      } else {
          (*last)-&gt;nextvertex = v;
          *last = v;
      }
  }
  
  void graph_edge(ge from, ge to, vertex **root, vertex **last)
  {
      vertex *temp = *root;
      vertex *fromptr, *toptr;
      int count = 0;
      while (temp != NULL) {
          // ensure both the vertices are present before drawing an edge
          if (temp-&gt;element == from) {
              fromptr = temp;
              count++;
          }
          if (temp-&gt;element == to) {
              toptr = temp;
              count++;
          }
  
          temp = temp-&gt;nextvertex;
      }
      if (count &lt; 2) {
          printf("either %c or %c vertices do not exist in graph\n", from, to);
          return;
      }
  
      edge *node = fromptr-&gt;nextedge;
      while (node != NULL) {
          printf("found edge %c%c\n", fromptr-&gt;element, node-&gt;link-&gt;element);
          node = node-&gt;nextedge;
      }
      edge *newedge = malloc(sizeof(*newedge));
      newedge-&gt;nextedge = NULL;
      newedge-&gt;link = toptr;
      node = newedge;
      printf("val is %c\n", fromptr-&gt;nextedge-&gt;link-&gt;element);
  }
  
  int main(int argc, char **argv)
  {
      // keep track of head
      vertex *root = malloc(sizeof(*root));
      root-&gt;nextvertex = NULL;
      root = NULL;
  
      // keep track of last vertext
      vertex *last = malloc(sizeof(*last));
      last-&gt;nextvertex = NULL;
  
      last = root;
  
      graph_add('a', &amp;root, &amp;last);
      graph_add('b', &amp;root, &amp;last);
      graph_add('c', &amp;root, &amp;last);
      graph_add('d', &amp;root, &amp;last);
  
      graph_edge('a', 'b', &amp;root, &amp;last);
      graph_edge('a', 'c', &amp;root, &amp;last);
      graph_edge('b', 'c', &amp;root, &amp;last);
      graph_edge('a', 'd', &amp;root, &amp;last);
  
      return 0;
  }
  </code></pre>