我可以用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);
会有用的.
在c语言中如何使用gcc实现这一点?我有
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