如何使用匿名结构/联合来编译C代码?

我可以在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


皈依舞
浏览 593回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP