second draft: add Bitfields to D

Timon Gehr timon.gehr at gmx.ch
Tue May 7 18:55:27 UTC 2024


On 5/7/24 05:39, Walter Bright wrote:
> The most practical thing is to make it mean the size of the memory 
> object the bitfield is a subset of.

I agree that given the C-like bitfield design you seem to have set your 
mind on, and given the behavior of `.offsetof` this is a decent behavior 
for `.sizeof`.

However, this is not what the DIP currently says, so it should be updated.

> Unless (unimplemented) packed 
> bitfields are used, the sizeof is the size of the type.

The size of the memory object has to be whatever the associated C 
compiler allocates, and according to the standard, it is in principle 
allowed to pack by default. There is no guarantee that the memory object 
is in fact at least as big as the type of the bitfield. I am not 
familiar with bitfield layout on all platforms that D supports via GDC 
and LDC, but I would not be surprised if on some of them this is 
actually an issue in practice.


More information about the dip.development mailing list