DIP: add Bit Fields
Tim
tim.dlang at t-online.de
Sat Mar 9 13:17:54 UTC 2024
On Thursday, 7 March 2024 at 22:28:34 UTC, Dennis wrote:
> Why bow down to C and treat D as a second class citizen? The
> DIP should really substantiate this alleged importance of
> C-compatibility of non-ImportC D bitfields: Can you name at
> least one dub package that would benefit from bit fields with
> C-compatible layout?
Qt uses bitfields in some headers, e.g. here:
https://github.com/qt/qtbase/blob/4e158f6bfa7d0747d8da70b3b15a44b52e35bb8a/src/corelib/kernel/qtimer.h#L239
My bindings emulate the bitfields with a single field and
accessor functions:
https://github.com/tim-dlang/dqt/blob/2afa4adcec0a6905b11256f403c6136277a6c96a/core/qt/core/timer.d#L217
Bitfields in D could be used instead, but they would need to be
compatible with C++ for extern(C++) types.
Sometimes bitfield members are disabled with the preprocessor:
https://github.com/qt/qtbase/blob/4e158f6bfa7d0747d8da70b3b15a44b52e35bb8a/src/corelib/time/qdatetime.h#L259
This could be translated to version statements in D.
Most of the times bitfields for Qt are not a big problem, because
they are only private members of the types.
More information about the dip.development
mailing list