title: Error: expected specifier-qualifier-list before
body: <p>I am trying to write code to build a stack, but I'm getting compilation errors which don't make sense to me. Here is my <code>stack.h</code>:</p>
  
  <pre><code>struct StackNode {
  
      void* previous;
      int   value;
  };
  
  
  struct Stack {
  
      StackNode* top;
  };
  
  
  Stack* new_stack () {
  
      StackNode stn = { NULL, 0 };
      Stack* st  = (Stack*) malloc(sizeof(Stack));
      st-&gt;top = NULL;
      return st;
  }
  </code></pre>
  
  <p>and my <code>main.c</code>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include "stack.h"
  
  int main () {
  
      struct Stack* st = new_stack();
  
      return 0;
  
  }
  </code></pre>
  
  <p><code>gcc</code> throws these errors:</p>
  
  <blockquote>
    <p>make (in directory: /home/diego/temp/stack) gcc -g -O2 -std=c99 -c</p>
    
    <p>main.c In file included from main.c:4: Compilation failed. stack.h:10:</p>
    
    <p>error: expected specifier-qualifier-list before ‘StackNode’</p>
    
    <p>stack.h:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘<strong>attribute</strong>’</p>
    
    <p>before ‘*’ token main.c: In function ‘main’: main.c:8: warning:</p>
    
    <p>implicit declaration of function ‘new_stack’ main.c:8: warning:</p>
    
    <p>initialization makes pointer from integer without a cast make: <em>*</em></p>
    
    <p>[main.o] Error 1</p>
  </blockquote>
  
  <p><strong>EDIT</strong>: I found the error. I forgot to put <code>struct</code> before <code>Stack</code> and <code>StackNode</code> in some lines. Always having <code>struct</code> on those lines solves the issue.</p>