second draft: add Bitfields to D

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Apr 28 03:02:49 UTC 2024


On Saturday, April 27, 2024 6:31:37 PM MDT Adam Wilson via dip.development 
wrote:
> On Tuesday, 23 April 2024 at 01:01:11 UTC, Walter Bright wrote:
> > https://github.com/WalterBright/documents/blob/dcb8caabff76312eee25bb9aa05
> > 7774d981a5bf7/bitfields.md
> I would approve this because we gain C compatibility and we can
> drop the `std.bitmanip.bitfields` type entirely from Phobos 3.

Actually, it doesn't fix the need for std.bitmanip.bitfields, though it does
reduce it. Use cases that need a guaranteed layout (e.g. for serialization)
won't work with C-compatible bitfields, because the layout could change
depending on the target platform. So adding this feature to the language
doesn't help them at all, and they'd still need something like the Phobos
solution.

Of course, this DIP helps quite a bit with regards to C bindings (which the
Phobos solution does not help with), because those cases need to match the C
layout rather than guaranteeing a layout that will be the same across all
OSes and architectures. This DIP could also be used in cases where you don't
care what C is doing, but you also don't care exactly how the bitfields are
laid out. So, it would reduce the need for a Phobos solution, but it doesn't
replace it.

- Jonathan M Davis





More information about the dip.development mailing list