initialize a union array at declaration

夙愿已清 提交于 2019-12-05 07:19:17

Quoting this page:

With C89-style initializers, structure members must be initialized in the order declared, and only the first member of a union can be initialized.

So, either put the float array first, or if possible use C99 and write:

mat m[2] = { { .f = { /* and so on */ } }, /* ... */ };

The important thing being the .f.

You need to indicate which union field you are initializing. Try using this syntax:

mat m[2] = {
    {.f = {30467.14153,5910.1427,15846.23837,7271.22705}},
    {.f = {30467.14153,5910.1427,15846.23837,7271.22705}}
};

This successfully compiled for me, without any warnings.

Try to change members:

typedef union {
    float f[4];
    __m128d m;
} mat;
mat m[2] = { { {30467.14153,5910.1427,15846.23837,7271.22705},
               {30467.14153,5910.1427,15846.23837,7271.22705} } };

If you initialize union without member specification like .f = { ... } then first member of union is initialized.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!