C struct -> D struct (alignment hacks)

Mike vertex at gmx.at
Wed Feb 4 12:28:29 PST 2009


On Wed, 04 Feb 2009 21:04:16 +0100, Jarrett Billingsley  
<jarrett.billingsley at gmail.com> wrote:

> Nope.  The C struct is defining a bitfield; a and b will actually be
> contained within a single 4-byte field.  Your D version defines three
> integers.
>
> Unfortunately the C specification does not specify any required
> ordering for bitfields, padding, ordering etc.  Fortunately, most
> compilers just put them in order, starting from the lowest bits.
>
> What you'll have to do, then, is put a single int field that
> corresponds to the C struct's bitfields.  Then, have methods which
> shift and mask the bits to get and set the individual bitfields.  htod
> will do this for you, if you're on windows and just want to run an .h
> file containing that struct through it.

Thanks. I tried htod with Wine, and although it runs it can't open include  
files, so I thought I'd translate the headers manually. However - I found  
more of those bitfields; I'll better find a machine with Windows then :)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list