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: Structure layout in big/little endian modes


On Wednesday 23 of November 2011 19:33:01 ÐÐÐÐÐÐÐÑ ÐÐÐÑÐÐÐ wrote:
> Hello all!
> 
> I have some lack of understanding how to write endianness independent
> definition of structure, which contains bit fields.
> 
> For example, field, containing endpoint address in endpoint descriptor
> of USB device, can be defined as follow:
> 
> struct EndpointAddress
> {
>     UnsignedByte EndpointNumber: 4;
>     UnsignedByte: 3;
>     UnsignedByte TransferDirection: 1;
> };
> 
> All USB descriptors have little endian byte order (and filling
> starting from least significant bit). If I would run some code which
> uses such definition on big endian CPU, I will get incorrect result.

some times ago i've established a nice c++ wrapper for byteorder conversion
and operation on bits/bytes ranges. please see for core source parts on
 http://pluto.agmk.net/src/portable_bit_masking.tgz



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