Union and struct packing problem

后端 未结 5 2050
无人共我
无人共我 2021-01-02 20:55

I\'m writing some software where each bit must be exact(it\'s for the CPU) so __packed is very important.

typedef union{
uint32_t raw;
struct{
    unsigned          


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 21:24

    If the exact position of bits matters, your safest bet is explicit packing and unpacking of the structure into an unsigned char array. Anything else is too implementation dependent.

提交回复
热议问题