在 4D 矩阵类型中使用匿名结构时的警告
我试图在 C 中定义一个封装的 4 维矩阵类型(用于 iOS/ObjC 环境)(因此不是裸数组),并且可以使用索引值或通过命名结构成员进行访问。这是我的尝试:
typedef union {
float m[16];
struct {
struct {
float x;
float y;
float z;
float w;
} x;
struct {
float x;
float y;
float z;
float w;
} y;
struct {
float x;
float y;
float z;
float w;
} z;
struct {
float x;
float y;
float z;
float w;
} w;
}; // warning here "Declaration does not declare anything"
} Matrix4;
这有效,但由于匿名(未命名)结构,我收到警告。我显然不想命名该容器结构,因为它仅用于保存四个内部结构。
此页面暗示我应该能够做到这一点? http://gcc.gnu.org/onlinedocs/gcc/Unnamed -Fields.html#Unnamed-Fields
它似乎实际上工作,那么这是错误的,或者如果不是,我应该如何摆脱警告?
我正在使用 LLVM GCC 4.2。
感谢您的任何见解或建议。
I'm trying to define a 4-d matrix type in C (for use in the iOS/ObjC environment) that is encapsulated (so not a bare array), and that can be accessed using indexed values or via named struct members. This is my attempt:
typedef union {
float m[16];
struct {
struct {
float x;
float y;
float z;
float w;
} x;
struct {
float x;
float y;
float z;
float w;
} y;
struct {
float x;
float y;
float z;
float w;
} z;
struct {
float x;
float y;
float z;
float w;
} w;
}; // warning here "Declaration does not declare anything"
} Matrix4;
This works, but I get a warning due to the anonymous (unnamed) struct. I obviously don't want to name that container struct as it only serves to hold the four inner structs.
This page implies that I should be able to do this?
http://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html#Unnamed-Fields
It seems to actually work, so is this wrong, or if not, how should I get rid of the warning?
I'm using LLVM GCC 4.2.
Thanks for any insight or suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在允许匿名结构和联合(从 C11 开始)。当您迁移到更新的编译器时,您的担忧最终会消失。在 GCC 中,添加
-std=c1x
。Anonymous structs and unions are now allowed (as of C11). Your worries will eventually go away as you migrate to a newer compiler. In GCC, add
-std=c1x
.