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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 21 18:12:59 UTC 2022


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

elpenguino+D at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |elpenguino+D at gmail.com

--- Comment #2 from elpenguino+D at gmail.com ---
(In reply to johanengelen from comment #1)
> 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...

D doesn't need two undefined flavours of bitfields. Some people find it useful
to be able to read bitfields from files or the network regardless of cpu
architecture.

--


More information about the Digitalmars-d-bugs mailing list