Why does an 8-bit field have endianness?

后端 未结 6 2135
天命终不由人
天命终不由人 2021-02-07 10:58

See the definition of TCP header in /netinet/tcp.h:

struct tcphdr
  {
    u_int16_t th_sport;         /* source port */
    u_int16_t th_dport;         /* destin         


        
6条回答
  •  旧巷少年郎
    2021-02-07 11:36

    My understanding is that bit ordering and endianness are generally two different things. Structures with bit-fields are generally not portable across compilers/architectures. Sometimes ifdefs can be used to support different bit orderings. In this case the endianness is really irrelevant and it should be an ifdef about the bit ordering. The assumption that some endianesses have a certain bit-order may be true in some cases.

提交回复
热议问题