Почему Битовый порядок байтов является проблемой в битовых полях?

Кажется, что любой переносимый код, использующий битовые поля, различает платформы с прямым и обратным порядком байтов. См. объявление struct iphdr в ядре Linux для примера такого кода.

 struct ParsedInt {
 беззнаковый int f1: 1;
 беззнаковое int f2: 3;
 беззнаковое int f3: 4;
};
uint8_t i;
struct ParsedInt * d = & i;
Here, writing d->f2 is simply a compact and readable way of saying (i>>1) & (1.

However, bit operations are well-defined and work regardless of the architecture. So, how come bitfields are not portable?

54
задан Leonid99 17 May 2011 в 23:50
поделиться