c - 错误 : expected '=' , ','、 ';'、 'asm' 或 '__attribute__' 之前的 'stackEmpty'

标签 c compiler-errors

此代码用于在 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/

相关文章:

c - 显示包含空格的字符串中每个单词的第一个字母

java - 如何编译这个项目

C# 变量和常量在溢出期间的行为不同。

java - 错误 : Could not find or load main class . .. - Eclipse 之外的 Maven 项目

c - C语言中如何判断用户输入的数据是否为 float ?

c - 初始化某个结构的大数组——出现段错误

位域与(负)整数、未定义行为或编译器错误的比较?

c++ - 在不使用预编译头文件的 C++ 项目中编译 C 文件?

python - 尝试安装 pyamg : clang: error: no such file or directory: '“-I/.../boost_1_59_0” ' 时出错

c - 作为结构变量传递的整数数组