www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bit fields in struct, why doesn't D support them?

reply Jeremie Pelletier <jeremiep gmail.com> writes:
I know this is an old subject, as this has been stated in the struct reference
page ever since D1, but I'm really wondering why the bit fields aren't
supported (or purposely not implemented?) in D.

Having this feature would greatly simplify a lot of code, and allow easier
interfacing with C structs using it.
May 19 2009
next sibling parent Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Tue, May 19, 2009 at 11:17 PM, Jeremie Pelletier <jeremiep gmail.com> wrote:
 I know this is an old subject, as this has been stated in the struct reference
page ever since D1, but I'm really wondering why the bit fields aren't
supported (or purposely not implemented?) in D.

 Having this feature would greatly simplify a lot of code, and allow easier
interfacing with C structs using it.

It actually wouldn't, since C doesn't specify any order to packing bitfields, whether there should be padding etc.
May 19 2009
prev sibling next sibling parent Lutger <lutger.blijdestijn gmail.com> writes:
Jeremie Pelletier wrote:

 I know this is an old subject, as this has been stated in the struct reference
page ever since D1, but I'm really wondering why the bit fields aren't
supported (or purposely not implemented?) in D.
 
 Having this feature would greatly simplify a lot of code, and allow easier
interfacing with C structs using it.

In D2 it is supported by phobos: http://www.digitalmars.com/d/2.0/phobos/std_bitmanip.html
May 19 2009
prev sibling parent Brad Roberts <braddr puremagic.com> writes:
Jeremie Pelletier wrote:
 I know this is an old subject, as this has been stated in the struct reference
page ever since D1, but I'm really wondering why the bit fields aren't
supported (or purposely not implemented?) in D.
 
 Having this feature would greatly simplify a lot of code, and allow easier
interfacing with C structs using it.

Google is your friend. This thread has happened at least once in the past already. Before rehashing it, might as well catch up on the past discussion: http://www.digitalmars.com/d/archives/digitalmars/D/proper_bit_fields_in_the_D2_language_88506.html Later, Brad
May 19 2009