__LITTLE_ENDIAN_BITFIELD和__BIG_ENDIAN_BITFIELD? [英] __LITTLE_ENDIAN_BITFIELD and __BIG_ENDIAN_BITFIELD?

查看:129
本文介绍了__LITTLE_ENDIAN_BITFIELD和__BIG_ENDIAN_BITFIELD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道内核的编译器将如何使用不同的字节序位域:

I want to know what compiler of kernel will do with different endian bitfield:

struct iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u8
    ihl:4,
    version:4;
#elif defined (__BIG_ENDIAN_BITFIELD)
__u8
    version:4,
    ihl:4;
#else
    #error "Please fix <asm/byteorder.h>"
#endif
......
};

推荐答案

结构 iphdr 占用1个字节.在小端机中,第一个字段 ihl 占据位0、1、2、3,第二个字段 version 占据位4、5、6、7. ihl 列在最前面,并获得最低有效位.在第二种情况下,首先列出的 version 将获得第一位.由于这是大字节序,因此第一个位是位7、6、5、4. ihl 获得下4位,即3、2、1,0.

The structure iphdr takes up 1 byte. In a little endian machine, the first field ihl occupies bits 0,1,2,3 and the 2nd field version occupies bits 4,5,6,7. ihl is listed first and gets the least significant bits. In the seconds case, version, being listed first gets the first bits. Since this is big endian, the first bits are bits 7,6,5,4. ihl get the next four bits, 3,2,1,0.

在#if条件下,无论是在大端机还是小端机中进行编译,这些位都位于字节中相同的位偏移位置.

With the #if condition, regardless is one compiles in a big or little endian machine, the bits are in the same bit offset location within a byte.

在这些字段位于相同的位本地化的情况下,各种掩蔽和移位操作给出的结果相同.

With these field in the same bit localization, various masking and bit shift operations give the same result.

有趣的是,这个故事格列佛游记起源于小尾数法和大尾数法.在那里,人们争辩说,一个煮熟的鸡蛋的哪一端首先破裂是一场毫无意义的战争.因此,大字节序与小字节序.一个无意义的辩论的恰当名称,关于哪个更正确.(我有点字节序.)

Interestingly the phrase little endian and big endian originate for the the story Gulliver's Travels. There, folks argue a senseless war about which end of a hard-boiled egg to crack first. Thus big endian vs. little endian. An apt name for a senseless debate about which is more correct. (I'm a little endian-er.)

此外,同一故事还引入了另一个计算机术语:雅虎.

Further, the same story introduces another computer term: yahoo.

这篇关于__LITTLE_ENDIAN_BITFIELD和__BIG_ENDIAN_BITFIELD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆