title: C - Error returning structure pointer across multiple files
body: <p>I am trying to learn how to separate C code into multiple files, but I am running into an error when doing so.</p>
  
  <p>Relevant code (separated by file):</p>
  
  <p>ex6.h:</p>
  
  <pre><code>#ifndef __ex6_h__
  #define __ex6_h__
  
  struct nlist { /* table entry: */
      struct nlist *next; /* next entry in chain */
      char *name; /* defined name */
      char *defn; /* replacement text */
  };
  
  #endif
  </code></pre>
  
  <p>list.c:</p>
  
  <pre><code>#include "ex6.h"
  
  struct nlist *install(char *name, char *defn)
  {
      struct nlist *np;
      unsigned hashval;
  
      if ((np = lookup(name)) == NULL) { /* not found */
          np = (struct nlist *) malloc(sizeof(*np));
          if (np == NULL || (np-&gt;name = strdup(name) == NULL)
              return NULL;
          hashval = hash(name);
          np-&gt;next = hashtab[hashval];
          hashtab[hashval] = np;
      } else /* already there */
          free((void *) np-&gt;defn); /*free previous defn */
      if ((np-&gt;defn = strdup(defn)) == NULL)
          return NULL;
      return np;
  }
  </code></pre>
  
  <p>main.c:</p>
  
  <pre><code>#include "ex6.h"
  
  int main (int argc, char* argv[])
  {
      struct nlist *np1;
  
      np1 = install("This", "That");
  
      return 0;
  }
  </code></pre>
  
  <p>When I compile this code, I get this:</p>
  
  <pre><code>cc -g main.c list.c -o main
  main.c: In function ‘main’:
  main.c:10:6: warning: assignment makes pointer from integer without a cast [enabled by default]
    np1 = install("This", "That");
    ^
  </code></pre>
  
  <p>There is obviously more code than this (will post if requested), but every other part of the code seems to work fine except this snippets. Also, when I put the code from my "main.c" file and "list.c" into the same file the the code works fine.</p>
  
  <p>Any help is appreciated!</p>