proper bit fields in the D2 language?

Mattias Holm mattias.holm at openorbit.REMOVE.THIS.org
Mon Apr 27 13:02:32 PDT 2009


> Bitfields in Phobos are defined portably: always populated from lsb to 
> msb, the total size must be 8, 16, 32, or 64, and there is no hidden 
> padding (you obtain padding with anonymous fields).
> 
> Andrei

If this is the case, the bitfields are not portable and the behaviour is 
the same as for GCC, except it is reversed.

The order should be:

LSByte to MSByte on little endian machines
MSByte to LSByte on big endian machines


This means that bitfields are defined in human readable order with 
respect to the physical layout on the machine.

The point being:

struct {
   uint a:4;
   uint b:28;
}

should give a structure:
  _ _______
|.|.......|

where each dot represents 4 bits. And this structure should be identical 
if the data is moved between different systems, that is a TCP header 
definition mapping into a byte stream, should be identical on both PPC 
and x86. If the LSB to MSB ordering is used in phobos, then the 
bitfields are as useful as the GCC bitfields, i.e. not at all.


/Mattias



More information about the Digitalmars-d mailing list