Union and struct packing problem

后端 未结 5 2047
无人共我
无人共我 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:15

    You don't mention that you are clearing out the bits of the structure beforehand, are you sure you aren't ending up with garbage bits left over in the first case?

    // maybe try this
    page_union_t p = {0};
    

提交回复
热议问题