C Bitfields in D

Stanislav Blinov stanislav.blinov at gmail.com
Tue Dec 7 13:17:58 PST 2010


bearophile wrote:
> Stanislav Blinov:
> 
>> I'm under the impression that
>>
>> struct my_struct
>> {
>> mixin(bitfields!(
>> uint, "i", 1,
>> uint, "", 31));
>> }
>>
>> should do the trick.
> 
> But bitfields in C may not use the same alignments used by bitfields!() on DMD so I think you have to test the sanity of the whole thing for each combination of D compiler, operating system and C compiler.
> 
> Bye,
> bearophile

hm... what alignments are you talking about? bitfields template uses the 
  smallest suitable type for all fields, which is uint for the above 
struct. The trouble may come from bit order, mayhaps. bitfields 
positions fields in LSb order.


More information about the Digitalmars-d-learn mailing list