[Issue 23573] std.bitmanip.bitfields doesn't respect native endianness

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 21 13:31:39 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23573

johanengelen at weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johanengelen at weka.io

--- Comment #1 from johanengelen at weka.io ---
I thought that `std.bitmanip.bitfields` does not give any guarantees on layout,
just that it tries to pack bits in minimal storage space.
For example also no guarantees when sending std.bitmanip.bitfields as ubyte[]
over network connection to a PC with different OS/arch.
Removal of guarantees (like no guarantees of class layout) enables reordering
of fields if it is beneficial to prevent accessing multiple bytes/words for
multibyte fields:
    mixin(bitfields!(
        bool, "flag1" , 1, 
        ubyte, "flag2", 8,  // spans 2 bytes or one byte?
        bool, "sign"  , 1));

Because D bitfields are meant to mimic C bitfields, I think it will be very
hard to guarantee that the layout of std.bitmanip.bitfields is the same...

--


More information about the Digitalmars-d-bugs mailing list