使用枚举时 c 中出现奇怪的编译错误
你好,在我的头文件 Data.hi 中将布尔类型定义为枚举,但出现编译错误,我不明白为什么:
// Data.h
// Author : Alexandre rousset
typedef enum {NO, YES} bool;
typedef struct stud {
char *date;
char *name; /* student name */
} Student;
void studentInit(Student *new);
bool studentPassExam(Student *s);
我收到此错误:
include/Data.h:4: error: two or more data types in declaration specifiers
include/Data.h:4: warning: useless storage class specifier in empty declaration
感谢您的帮助。
Hello in my header file Data.h i define a boolean type as an enumeration, but got a compile error and i don't understand why :
// Data.h
// Author : Alexandre rousset
typedef enum {NO, YES} bool;
typedef struct stud {
char *date;
char *name; /* student name */
} Student;
void studentInit(Student *new);
bool studentPassExam(Student *s);
I got this error :
include/Data.h:4: error: two or more data types in declaration specifiers
include/Data.h:4: warning: useless storage class specifier in empty declaration
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码可以使用
gcc version 4.6.2
正常编译。对于您的编译器来说,
bool
可能是一个内置类型。然而,根据标准(C89、C99),事实并非如此。在编译器中寻找强制执行标准兼容行为的选项。(以防万一,请确保您使用 C 而不是 C++ 编译器。但是,如果您使用过 C++ 编译器,那么它也应该抱怨
new
。因为new
是一个C++ 中的关键字。)Your code compiles fine with
gcc version 4.6.2
.Probably for your compiler
bool
is a built-in type. However, according to Standards (C89, C99) it is not. Look for options in your compiler which enforce standard compliant behavior.(Just in case, make sure you use C and not C++ compiler. However if you have used C++ compiler, than it should have complained about
new
too. Sincenew
is a keyword in C++.)