Can a union be initialized in the declaration?

c, declaration, initialization, unions

Solution

Use an initializer list:

U_U32_F u = { 0xffffffff };

You can set other members than the first one via

U_U32_F u = { .f = 42.0 };

Problem

For example, say we have a union ``` typedef union { unsigned long U32; float f; }U_U32_F; ``` When a variable of this union type is declared, is there a way to set an initial value? ``` U_U32_F u = 0xffffffff; // Does not work...is there a correct syntax for this? ```

Original source