スタックを実装しようとしていますが、不透明ポインターの使用法を理解していません。私の申告書です:
/* incomplete type */
typedef struct stack_t *stack;
/* create a new stack, have to call this first */
stack new_stack(void);
そして、これが私のスタック構造と new_stack 関数です:
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;
}
私の目には、新しいスタックのアドレスを返していますが、これは new を返すことからコンパイル時にエラーをスローします。私は何を間違っていますか?