C 中的语法错误
5 enum state {ST_BEFORE_KEY, ST_IN_KEY, ST_BEFORE_VALUE, ST_TERM, ST_ERR};
6
7 typedef struct {
8 state st;
...
上面的代码报告:
error: expected specifier-qualifier-list before ‘state’
使用枚举类型有什么问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
枚举状态
或包含typedef枚举状态
。在 C 中,枚举标记与标识符(变量、函数或 typedef)位于不同的命名空间中。
Use
enum state
or includetypedef enum state state
.Enumeration tags are in a different namespace in C than identifiers (variables, functions or typedefs).
尝试
稍微链接到此常见问题解答条目。这是关于命名空间的讨论。
有四种不同类型的命名空间,用于:
和枚举;这三个不是
即使他们分开
理论上可以);
每个结构或联合的命名空间);
和
变量、typedef 名称、枚举
常数),称为“普通
标准中的“标识符”。
编辑
由于OP要求提供示例..
Try
Marginally linked to this FAQ entry. And here's a discussion on namespaces.
There are four different kinds of namespaces, for:
and enumerations; these three aren't
separate even though they
theoretically could be);
namespace per structure or union);
and
variables, typedef names, enumeration
constants), termed ``ordinary
identifiers'' by the Standard.
EDIT
Since the OP is asking for an example..
如果你用c++就可以了;
在c(不是c++)上你应该这样写。
If you use c++, it is ok;
on c ( not c++) you should write like this.
你需要
You need