This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bit Field Formations


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).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]