【发布时间】:2018-11-08 08:02:51
【问题描述】:
有没有办法获得指向匿名结构的指针?如果没有匿名结构,我可以编写以下内容:
struct a{
int z;
};
struct b{
int y;
struct a *x;
}
这很好用,但我只在struct b 中使用struct a,用它污染全局命名空间似乎是多余的。有没有办法可以定义一个指向匿名结构的指针 (x)。可能如下所示:
struct b{
int y;
struct {
int z;
} *x;
}
或者这本身是否有效?
【问题讨论】:
-
"但我只在
struct b中使用struct a" 显然,你没有。或者你到底在哪里分配这个指针?在这个地方,你可能还需要参考struct a。
标签: c