[英]Syntax error in C
5 enum state {ST_BEFORE_KEY, ST_IN_KEY, ST_BEFORE_VALUE, ST_TERM, ST_ERR};
6
7 typedef struct {
8 state st;
...
The above code reports:上面的代码报告:
error: expected specifier-qualifier-list before ‘state’
What's wrong here in using enum type?使用枚举类型有什么问题?
Use enum state
or include typedef enum state state
.使用enum state
或包括typedef enum state state
。
Enumeration tags are in a different namespace in C than identifiers (variables, functions or typedefs).枚举标签在 C 中的命名空间与标识符(变量、函数或类型定义)不同。
Try尝试
enum state {ST_BEFORE_KEY, ST_IN_KEY, ST_BEFORE_VALUE, ST_TERM, ST_ERR};
typedef struct {
enum state st;
...
};
Marginally linked to this FAQ entry .勉强链接到这个常见问题条目。 And here's a discussion on namespaces .这是关于命名空间的讨论。
There are four different kinds of namespaces, for:有四种不同类型的命名空间,用于:
EDIT编辑
Since the OP is asking for an example..由于OP要求举个例子..
struct foo {
int bar;
int foo;
};
struct bar {
int foo;
struct foo bar;
};
If you use c++, it is ok;如果你用c++就可以了;
on c ( not c++) you should write like this.在 c(不是 c++)上,你应该这样写。
5 enum state {ST_BEFORE_KEY, ST_IN_KEY, ST_BEFORE_VALUE, ST_TERM, ST_ERR};
6
7 typedef struct {
8 enum state st;
You need你需要
typedef struct {
enum state st;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.