sem*_*maj 26 c initialization declaration unions
例如,假设我们有一个联盟
typedef union {
unsigned long U32;
float f;
}U_U32_F;
Run Code Online (Sandbox Code Playgroud)
声明此union类型的变量时,有没有办法设置初始值?
U_U32_F u = 0xffffffff; // Does not work...is there a correct syntax for this?
Run Code Online (Sandbox Code Playgroud)
Chr*_*oph 33
使用初始化列表:
U_U32_F u = { 0xffffffff };
Run Code Online (Sandbox Code Playgroud)
您可以设置除第一个之外的其他成员
U_U32_F u = { .f = 42.0 };
Run Code Online (Sandbox Code Playgroud)