title: C linked-list append to head or tail?
body: <p>I am looking at this code, implementing an insert operation of an element in a doubly linked-list. I am trying to grasp why the <code>LIST_APPEND</code> macro appends it to the end of the list, however, I always explain it to myself to be at the head. Code: </p>
  
  <pre><code>struct link {
      struct link *prev;
      struct link *next;
  };
  
  void insert(struct link *prev, struct link *new, struct link *next)
  {
      prev-&gt;next = new;
      new-&gt;prev = prev;
      next-&gt;prev = new;
      new-&gt;next = next;
  }
  
  #define LIST_APPEND(member, list, new)    \
      insert(list.prev, &amp;(new-&gt;member), &amp;list)
  </code></pre>
  
  <p>My considerations:</p>
  
  <p>Firstly, after the C-Preprocessor replaces the macro's content in the actual code, we get</p>
  
  <pre><code>void insert(list.prev, &amp;(new-&gt;member), &amp;list)
  {
      (list.prev)-&gt;next = (new-&gt;member);    //1.
      (new-&gt;member)-&gt;prev = list.prev;      //2.
      list-&gt;prev = (new-&gt;member);           //3.
      (new-&gt;member)-&gt;next = list;           //4.
  }
  </code></pre>
  
  <p>Which corresponds to:<br>
  1. The <code>next</code> of <code>list.prev</code> points to <code>(new-&gt;member)</code><br>
  2. The <code>prev</code> of <code>(new-&gt;member)</code> is now <code>list.prev</code><br>
  3. The <code>prev</code> of <code>list</code> is now <code>(new-&gt;member)</code><br>
  4. The next of <code>(new-&gt;member)</code> is <code>list</code><br></p>
  
  <p>If I had flows in my logic, they could have been here.</p>
  
  <p>Now to illustrate it, here is a possible (to my understanding) depiction of the insertion.</p>
  
  <p><a href="https://i.stack.imgur.com/71H2X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/71H2X.png" alt="linked-list"></a></p>
  
  <p><strong>Question</strong>: After all, is the append at the head or at the tail? If the latter where am I wrong?</p>