Bit Shifting, Masking or a Bit Field Struct?

前端 未结 3 1617
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 05:01

I\'m new to working with bits. I\'m trying to work with an existing protocol, which can send three different types of messages.

Type 1 is a 16-bit structure:

<
3条回答
  •  半阙折子戏
    2021-01-03 05:36

    You shouldn't use C structure bitfields because the physical layout of bitfields is undefined. While you could figure out what your compiler is doing and get your layout to match the underlying data, the code may not work if you switch to a different compiler or even update your compiler.

    I know it's a pain, but do the bit manipulation yourself.

提交回复
热议问题