DIP: add Bit Fields

Walter Bright newshound2 at digitalmars.com
Fri Mar 8 02:37:02 UTC 2024


The inconsistency of C bitfield layout is far less important than it is made out 
to be. Other inconsistencies C has: char/short/int/long sizes, 
float/double/longdouble behaviors, 1s or 2s complement arithmetic, field 
alignment and endianness. Even the signed-ness of chars is 
implementation-defined. D matches that behavior of the associated C compiler. 
Living with that is normal.

The gdc and ldc backends are written in C++. D bitfields would enable bitfields 
to be used in the D front end, and the backends can use them effortlessly 
(should be no problem for dtoh).

An important feature of D is interoperability with C (and to some extent C++). 
Reducing the friction as much as we reasonably can will lower the barriers to D 
adoption. It means D code can co-exist peacefully in the same binary. When gdc 
and ldc are ported to a different platform, with different C bitfield layouts, 
it will still *effortlessly* work correctly.

I like effortlessly.


More information about the dip.development mailing list