I am trying to implement a stack, but am not understanding the use of the opaque pointer. Here is my declaration:
/* incomplete type */
typedef struct stack_t *stack;
/* create a new stack, have to call this first */
stack new_stack(void);
And here is my stack structure and new_stack function:
struct stack_t {
int count;
struct node_t {
void *data;
struct node_t *next;
} *head;
};
stack new_stack(void)
{
struct stack_t new;
new.count = 0;
new.head->next = NULL;
return new;
}
In my eyes, I am returning the address of the new stack, but this throws an error on compilation from returning new. What am I doing wrong?