使用枚举时 c 中出现奇怪的编译错误

发布于 2024-12-19 06:33:25 字数 532 浏览 0 评论 0原文

你好,在我的头文件 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-12-26 06:33:25

您的代码可以使用 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. Since new is a keyword in C++.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文