second draft: add Bitfields to D

Steven Schveighoffer schveiguy at gmail.com
Fri Apr 26 15:26:06 UTC 2024


On Tuesday, 23 April 2024 at 01:01:11 UTC, Walter Bright wrote:
> https://github.com/WalterBright/documents/blob/dcb8caabff76312eee25bb9aa057774d981a5bf7/bitfields.md

Suffers from the same major problem as last time - nobody is 
going to be using C bitfield structs from D, yet we are 
inheriting all the problems. Keeping C compatibility is 
meaningless. We should pick one way and do it that way for D 
bitfields.

Have you considered that people might build some libraries with 
ldc, but build applications with dmd? If LDC picks one mechanism 
for laying out bitfields, but DMD picks a different one, then 
what happens when you try to use the two together? Do we really 
want to make D incompatible with itself?

This already happens with C. See for instance 
https://stackoverflow.com/questions/43504113/bitfield-struct-size-different-between-gcc-and-msft-cl

Adding more `__traits` is trivial, don't skimp here.

Still does not address `sizeof`.

The mechanism described to get the bit offset is... horrific. 
Please just add some `__traits`.

-Steve


More information about the dip.development mailing list