Warning when using anonymous structures in a 4D matrix type

176 views Asked by At

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.

1

There are 1 answers

2
Kerrek SB On

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.