我可以在 c++/g++ 中做到这一点:
struct vec3 {
union {
struct {
float x, y, z;
};
float xyz[3];
};
};
然后,
vec3 v;
assert(&v.xyz[0] == &v.x);
assert(&v.xyz[1] == &v.y);
assert(&v.xyz[2] == &v.z);
将工作。
使用 gcc 在 c 中如何做到这一点?我有
typedef struct {
union {
struct {
float x, y, z;
};
float xyz[3];
};
} Vector3;
但是我到处都有错误,特别是
line 5: warning: declaration does not declare anything
line 7: warning: declaration does not declare anything