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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 22 12:02:54 UTC 2022


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

--- Comment #5 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(In reply to Iain Buclaw from comment #4)
> It is not obvious to the observer that the mixin will generate code to match
> the layout for both big and little endian (depending on which is in effect).
Or more specifically - it's not obvious in the documentation that BigEndian
targets actually layout all fields in reverse.

https://dlang.org/library/std/bitmanip/bitfields.html

"""
The bits are filled in the order given by the parameters, starting with the
lowest significant bit.
"""

Strictly, both parts of this sentence contradict each other.  Because the
lowest significant bit on BigEndian is the "reverse order given".

"""
Create a bitfield pack of eight bits, which fit in one ubyte. The bitfields are
allocated starting from the least significant bit, i.e. x occupies the two
least significant bits of the bitfields storage.
"""

This should be clarified that `x` occupies the two least significant bits on
LittleEndian only.

--


More information about the Digitalmars-d-bugs mailing list