Bit Field Formations

Kevin P. Fleming kpfleming@starnetworks.us
Sat Jan 22 03:50:00 GMT 2005


Crescioli, Phil wrote:

> If I create a structure that includes bit-field definitions, how are the
> bit fields assigned within a word. In the example below, is variable x1
> assigned to bits 31-28 or bits 3-0? My assumption is that the fields are
> assigned in order so that the example produces either:

I believe that is implementation-defined. The compiler is free to use 
any method it likes to pack the bits into the structure. In fact, the 
identical compiler may organize the bits differently based on the 
architecture's endianness and alignment restrictions.

In other words, bitfields cannot be used reliably (if at all) for things 
that must be communicated outside the process the code is running in 
(except for another process running the same code on the same box, of 
course).



More information about the Gcc-help mailing list