C++ struct alignment question

后端 未结 6 822
清歌不尽
清歌不尽 2020-12-05 09:12

I have a predefined struct (actually several) where variables span across 32-bit word boundary. In Linux (and Windows using GCC) I am able to get my structs to pack to the

6条回答
  •  死守一世寂寞
    2020-12-05 09:46

    Alignment and ordering of bitfields are notoriously implementation-specific. It is much safer to declare a normal integer field and manipulate the "bitfields" within using masks and bitwise (| & ^) operators .

提交回复
热议问题