我正在尝试使用教科书作者给我的代码编写程序,但是在尝试编译使用该文件的程序时,每种方法都出现“取消引用指向不完整类型的指针”错误。下面是代码。有谁知道我如何修复这个作者的代码以使其正常工作?
#include <stdio.h>
#include <stdlib.h>
#include "StackADT.h"
#define STACK_SIZE 100
struct stackType {
int contents[STACK_SIZE];
int top;
};
static void terminate(const char *message) {
printf("%s\n", message);
exit(EXIT_FAILURE);
}
Stack create(void) {
Stack s = malloc(sizeof(struct stackType));
if (s == NULL) {
terminate("Error: Stack could not be created");
}
s->top = 0;
return s;
}
void destroy(Stack s) {
free(s);
}
void makeEmpty(Stack s) {
s->top = 0;
}
bool isEmpty(Stack s) {
return s->top == 0;
}
bool isFull(Stack s) {
return s->top == STACK_SIZE;
}
void push(Stack s, Item i) {
if (isFull(s)) {
terminate("Error: Stack is full");
}
s->contents[s->top++] = i;
}
int pop(Stack s) {
if (isEmpty(s)) {
terminate("Error: Stack is empty");
}
return s->contents[--s->top];
}
错误:
StackADT.c: In function 'create':
StackADT.c:29: error: dereferencing pointer to incomplete type
StackADT.c: In function 'makeEmpty':
StackADT.c:38: error: dereferencing pointer to incomplete type
StackADT.c: In function 'isEmpty':
StackADT.c:42: error: dereferencing pointer to incomplete type
StackADT.c: In function 'isFull':
StackADT.c:46: error: dereferencing pointer to incomplete type
StackADT.c: In function 'push':
StackADT.c:54: error: dereferencing pointer to incomplete type
StackADT.c:54: error: dereferencing pointer to incomplete type
StackADT.c: In function 'pop':
StackADT.c:62: error: dereferencing pointer to incomplete type
StackADT.c:62: error: dereferencing pointer to incomplete type