此代码用于在 C 中实现通用堆栈功能。
Code for stack.h
-------------
typedef struct{
void *elements;
int elementSize;
int logofElementsLength;
int allocatedLength;
}stack;
bool stackEmpty(const stack *s);
Client.c中的实现代码
bool stackEmpty(const stack *s)
{return (s->logLength==0);
}
错误
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'stackEmpty'
评论
代码以其他方式编译,我只在这一行收到错误。显然,错误必须来自这行代码。我正在使用
gcc -O0 -g3 -Wall -arch i386 -c -fmessage-length=0 -MMD -MP -MF"Client.d" -MT"Client.d" -o"Client.o" "../Client.c"
编译。
我在 MAC Snow Leopard OS 上运行。我在我的 Client.c
中导入了 stack.h
并且所有其他代码都可以正常编译和运行。任何帮助将不胜感激。
最佳答案
好吧,与 C++ 不同,bool
在 C 中不是有效类型(当然除非使用 stdbool.h
)。我见过 bool
在 C 中以这种方式使用:
typedef enum { false, true } bool;
关于c - 错误 : expected '=' , ','、 ';'、 'asm' 或 '__attribute__' 之前的 'stackEmpty',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6324990/