【发布时间】:2014-08-23 11:18:09
【问题描述】:
我正在尝试为这样的结构中的变量创建别名:
typedef struct {
union {
Vector2 position;
float x, y;
};
union {
Vector2 size;
float width, height;
};
} RectangleF;
(请注意,我没有为工会命名,所以我不必写:'variable.unionname.x' 等)
但是,当我创建此结构的一些常量时,我收到“初始化程序覆盖此子对象的先前初始化”警告:
static const RectangleF RectangleFZero = {
.x = 0.0f,
.y = 0.0f, // warning
.width = 0.0f,
.height = 0.0f // warning
}
这样做有什么问题吗?如果没有,我怎样才能摆脱这个警告?
编辑:我现在使用的解决方案:
typedef struct {
union {
Vector2 position;
struct { float x, y; };
};
union {
Vector2 size;
struct { float width, height; };
};
} RectangleF;
【问题讨论】:
标签: c struct compiler-warnings c99 unions