Why bit endianness is an issue in bitfields?

后端 未结 7 2139
忘了有多久
忘了有多久 2020-11-22 03:12

Any portable code that uses bitfields seems to distinguish between little- and big-endian platforms. See the declaration of struct iphdr in linux kernel for an example of su

7条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 04:09

    The bit fields will be stored in a different order depending on the endian-ness of the machine, this may not matter in some cases but in other it may matter. Say for example that your ParsedInt struct represented flags in a packet sent over a network, a little endian machine and big endian machine read those flags in a different order from the transmitted byte which is obviously a problem.

提交回复
热议问题