DIP: add Bit Fields
Walter Bright
newshound2 at digitalmars.com
Mon Apr 22 07:09:09 UTC 2024
On 3/25/2024 9:39 AM, MrSmith wrote:
> My list of wishes:
> 1. bitfields imported from C should use `extern(C)`, this way they can use
> whatever layout C compiler uses.
> 2. D bitfields should be `extern(D)`, and work like `bitfields` mixin.
> 3. Allow specifying default value.
>
> Here is how C3 language does bitfields:
> https://c3lang.github.io/c3docs/types/#bitstructs
> It has guaranteed layout, allows specifying endinanness, optional overlaping of
> fields. It allows static arrays to be used as a backing type. Its bitfields are
> done trough a special kind of struct - `bitstruct`.
Thank you for the link to C3. I read it. Some problems are simply not worth
solving, and C3 goes too far.
You can get a consistent layout by simply declaring your bitfields as 'int'. I
know this is not specified anywhere, but it works.
More information about the dip.development
mailing list