title: Initialize a stack in C by setting pointer to NULL
body: <p>I'm trying to implement stack in C according to the following header (stack.h):</p>
  
  <pre><code>#ifndef STACK_H
  #define STACK_H
  
  /* An element from which stack is consisting */
  typedef struct stack_node_ss {
    struct stack_node_ss *next;    /* pointer to next element in stack */
    void *value;                  /* value of this element */
  } stack_node_s;
  
  /* typedef so that stack user doesn't have to worry about the actual type of
   * parameter stack when using this stack implementation.
   */
  typedef stack_node_s* stack_s;
  
  /* Initializes a stack pointed by parameter stack. User calls this after he
   * has created a stack_t variable but before he uses the stack.
   */
  void stack_init(stack_s *stack);
  
  /* Pushes item to a stack pointed by parameter stack. Returns 0 if succesful,
   * -1 otherwise.
  */
  int stack_push(void *p, stack_s *stack);
  
  /* Pops item from a stack pointed by parameter stack. Returns pointer to
   * element removed from stack if succesful, null if there is an error or
   * the stack is empty.
   */
  void *stack_pop(stack_s *stack);
  
  #endif
  </code></pre>
  
  <p>However, being new with C, I'm stuck at the stack_init function, I have written in stack.c:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include "stack.h"
  
  void stack_init(stack_s *stack) {
      (*stack)-&gt;value = NULL;
      (*stack)-&gt;next = NULL;
  }
  </code></pre>
  
  <p>The main program begins with:</p>
  
  <pre><code>  int *tmp;
    stack_s stack;
    stack_init(&amp;stack);
  </code></pre>
  
  <p>And this crashes my program with:</p>
  
  <pre><code>Program received signal EXC_BAD_ACCESS, Could not access memory.
  Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
  0x0000000100000abf in stack_init (stack=0x7fff5fbffb30) at stack.c:6
  6       (*stack)-&gt;value = NULL;
  </code></pre>
  
  <p>Can you hint me to the right track? Many thanks.</p>