Don't understand implementation of linked lists for stacks

I am having a hard time understanding the C implementation of a linked list for a stack. From what I understand, a linked list is a data type where the fist member is the data, and the second is a pointer to the next element of the stack.

I don't really get what the STACK **header item being passed is. Also, I am not sure exactly what is happening at the else statement. I know what should be happening, is the function should be creating a new element of STACK type, settings the new STACK pointer to null, and setting the STACK pointer of the item below it to point to the new item on the stack. The syntax is not something I am used to though, so I am not following the operations.

Likewise, I don't really understand what the STACK **head pointer is. I am not sure what the if(empty(*head)) is checking. I don't really understand what this function is doing at all. I know what should be happening is the element below the popped element should have its next pointer set to a null state, and the item popped should be returned and the STACK data item deleted.

Any help with better understanding this code, and linked lists in general, would be much appreciated.

wow, instead of passing pointers it is simpler to pass the position you want to put and let the stack implementation put it for you. Carrano's Data Abstraction and Problem Solving with C++ explained this.

empty(*head) checks if the stack is empty. Probably by checking if head == NULL. empty is probably a function or a macro defined somewhere.

*head = node;
The new top of the stack is the new node so this line changes the head (top) pointer to point to the new node.

It is an error to call pop on an empty stack so that is why they check if the stack is empty in pop.

123456789101112

// Make a copy of the top pointer.
STACK *top = *head;
// Make a copy of the top node's data.int value = top->data;
// Make the one below the top node to the new top of the stack.
*head = top->next;
// Free the old top node. This is why we had to make a copy of the top node // because *head no longer points to the old top.
free(top);
// Return the value of the "popped" top node. This is why we had to make a copy // of the data because the node containing the data no longer exists.return value;