C struct (with bitfields) to D and back

Mike Parker aldacron71 at yahoo.com
Sun Aug 6 22:38:01 PDT 2006

Jarrett Billingsley wrote:
> "Serg Kovrov" <kovrov at no.spam> wrote in message 
> news:eb5rcb$2nh$1 at digitaldaemon.com...
>> Thanks for reply, Jarrett, I hope it is.
>> I actually can't test it right now as Uniscribe is quite complicated 
>> subject, and I just started investigating it... As/if I get some results, 
>> I'll post it (and perhaps bindings to the API) here.
> I worked up a simple example with some oddly-sized bitfields, and it does 
> seem to work - I can link to the original C library using the htod'ed D 
> module, and it can read the struct bitfields that D produces.  This is using 
> DMC though, so it might not be compatible with other compilers.  Hopefully 
> other compilers order bitfields the same way DMC does. 

It would be nice if the C standard specified ordering for bitfields, but 
it's one of the many items left up to the compiler. That's why any 
solution you use in D to implement them has the potential to break when 
interacting with C output from different compilers. I'm not sure what 
the reality is, though.

More information about the Digitalmars-d-learn mailing list