Union initialization in C++ and C

后端 未结 3 1733
太阳男子
太阳男子 2021-02-12 01:17

I have built a working C library, that uses constants, in header files defined as

typedef struct Y {
  union {
    struct bit_field bits;
    uint8_t raw[4];
  }         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-12 01:52

    I had the same problem. For C89 the following is true:

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

    I found this explanation at: Initialization of structures and unions

提交回复
热议问题