嵌套结构定义
我正在处理计算机体系结构课程的模拟。我尝试使用 gcc v4.5.2 来编译 MSYS1.1/MinGW 包。
Makelog:
In file included from
sim-outorder.c:107:0: bpred.h:214:5:
error: expected specifier-qualifier-list before 'uint'
...
make: *** [sim-outorder.o] Error 1
我检查了bpred.h中的第214行,有一个嵌套结构定义为:
208 /* branch predictor update information */
209 struct bpred_update {
210 char *pdir1; /* direction-1 predictor counter */
211 char *pdir2; /* direction-2 predictor counter */
212 char *pmeta; /* meta predictor counter */
213 struct dir{ /* predicted directions */
214 uint bimod : 1; /* bimodal predictor */
215 uint twolev : 1; /* 2-level predictor */
216 uint meta : 1; /* meta predictor (0..bimod / 1..2lev) */
217 } dir;
218 };
这个结构块有什么问题? 你能帮忙吗? 谢谢!
I'm dealing with sim for computer architecture course. I try to compile package with MSYS1.1/MinGW with gcc v4.5.2.
Makelog:
In file included from
sim-outorder.c:107:0: bpred.h:214:5:
error: expected specifier-qualifier-list before 'uint'
...
make: *** [sim-outorder.o] Error 1
I checked the line 214 in bpred.h, there is a nested struct definition as:
208 /* branch predictor update information */
209 struct bpred_update {
210 char *pdir1; /* direction-1 predictor counter */
211 char *pdir2; /* direction-2 predictor counter */
212 char *pmeta; /* meta predictor counter */
213 struct dir{ /* predicted directions */
214 uint bimod : 1; /* bimodal predictor */
215 uint twolev : 1; /* 2-level predictor */
216 uint meta : 1; /* meta predictor (0..bimod / 1..2lev) */
217 } dir;
218 };
What's wrong with this struct block?
Could you please help??
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您被禁止命名内部结构:
我怀疑这是因为“说明符限定符列表”听起来像一个令牌,它是诸如 struct dim = {0}; 之类的东西的一部分。
I believe that you are disallowed from naming the inner struct:
I suspect this because a "specifier-qualifier-list" sounds like a token which is part of something like
struct dim = {0};
.在 C 中,内部结构不允许有名称,这是由于您通常需要如何在 C 中引用结构:
因此,天真的 C 编译器不清楚它是否应该期待变量或类型声明。
然而,在这种情况下,使用 C++ 编译器它会像您期望的那样工作,因为 C++ 不期望变量减速的结构前缀。
解决方案是从内部结构中删除该名称,或者在另一个结构之外声明它。
In C, inner structs are not allowed to have names, this is due to how you need to reference structures in C normally:
It is thus unclear to a naive C compiler if it is should be expecting a variable, or a type declaration.
This is a case where however, using a c++ compiler it would work as you expect it to, due to the fact C++ does not expect the struct prefix for variable decelerations.
The solution is to either remove the name from the inner struct, or declare it outside of the other struct.