Позволю заметить.
Стандарт не говорит каким будет представление bit-field в памяти, это на совести компилятора и архитектуры (big или little indian), НО:
#define FLAG_0 0x00000001
unsigned int x=0;
x = x | (FLAG_0);
и
union{
struct{
unsigned int FLAG0 : 1;
unsigned int : 31;
}bits;
unsigned int val;
}y
y.bits.FLAG0 = 1;
Будет полностью ролностью эквивалентно независимо от архитектур (расположения байт в памяти для Int, если слова меньше 32 бит).
Использование union+bitfields или флагов+переменные полностью эквивалентно.
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdfстраница 37:
Цитата
Values stored in unsigned bit-fields and objects of type unsigned char shall be
represented using a pure binary notation.40)
40) A positional representation for integers that uses the binary digits 0 and 1, in which the values
represented by successive bits are additive, begin with 1, and are multiplied by successive integral
powers of 2, except perhaps the bit with the highest position. (Adapted from the American National
Dictionary for Information Processing Systems.) A byte contains CHAR_BIT bits, and the values of
type unsigned char range from 0 to 2CHAR_BIT - 1.
Как уже отмечал, порядок байт в int зависит от компилера и платформы.
дополнение (начал перечитывать):
Цитата
10 An implementation may allocate any addressable storage unit large enough to hold a bitfield.
If enough space remains, a bit-field that immediately follows another bit-field in a
structure shall be packed into adjacent bits of the same unit. If insufficient space remains,
whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is
implementation-defined. The order of allocation of bit-fields within a unit (high-order to
low-order or low-order to high-order) is implementation-defined. The alignment of the
addressable storage unit is unspecified.
Если биты не влезли, то пакуются в в прилегающие биты (биту 0 прилегает бит 7) в такой же примитивный тип (char..int) как и предыдущие биты.
Если битов много, больше чем Int, то паковаться будет в два инта, а они могут располагаться в памяти в произвольных местах. Тут будет нужна прагма на упаковку вместе.
Или если операции идет с байтами, то паковка в байты идущие подряд, для многобайтовых полей не связаных в union.
Использовать union надо обязательно для примитивного типа:
Цитата
A union type describes an overlapping nonempty set of member objects, each of
which has an optionally specified name and possibly distinct type.
Ну стоит помнить что unsigned int может быть как 32 бита так и 16.
Ограничение определено как 16 и больше.
Цитата
The
minimum magnitudes shown shall be replaced by implementation-defined magnitudes
with the same sign.
#define UINT_MAX 65535