title: How to deal with incomplete definitions of types and forward declarations in interfaces and implementations
body: <p>Ok, let me preface this question.  This question has been asked, but not answered specifically for a case of not making changes to the .h file, so please do not link to a question that has been answered by saying "oh, move it to the .h file".  I am currently in a class where the teacher hands us the .h file and says, make an implementation to this and DO NOT CHANGE ANYTHING IN THE .h FILE.  I followed advice to move structs and such to the .h file on my previous project and was hit very hard on my grade because of that</p>
  
  <p>So, with that being said, let me post a bit of code and get to the nitty gritty.</p>
  
  <p>The .h file</p>
  
  <pre><code>#ifndef _list_h
  #define _list_h
  
  typedef char *ListItemP  //a pointer to an item in the list
  typedef struct List *ListP //a pointer to the List struct itself
  
  somefunctions();
  
  #endif
  </code></pre>
  
  <p>The .c file</p>
  
  <pre><code>#include "List.h"
  struct List
  {
      int foo;
      ListItemP bar;
  };
  
  ListP newList()
  {
      // implementation, I understand and am confident I used malloc 
      // and everything else correctly to make a new struct
  }
  </code></pre>
  
  <p>The main.c or tester.c or whatever you'd like to call it file where I test the implementation and interface (.c and .h respectively)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stlib.h&gt;
  #include "List.h"
  
  int main()
  {
       ListP n1 = newList();
       n1-&gt;foo = 5;
  
       return 0;
  }
  </code></pre>
  
  <p>These are the errors I am getting after compiling on my unix (osx) terminal with gcc -O List.c main.c</p>
  
  <pre><code> main.c:16:5: error: incomplete definition of type 'struct List'
  
   n1-&gt;foo = 5;
   ~~^
  
  ./List.h:21:16: note: forward declaration of 'struct List'
  
   typedef struct List *ListP;
             ^
   1 error generated.
  </code></pre>
  
  <p>Any help will be greatly appreciated, and if you insist on linking me to a previously asked question then please point out where in that question they answered my specific part of the problem. Maybe I missed it, but I feel as if I've checked through these questions pretty thoroughly.  This problem has been plaguing me since the beginning of this course, so a snippet of code could set me straight but man I'd love an explanation so I can finally understand what I'm doing wrong.  Thank you thank you thank you.</p>