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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 22 18:17:43 UTC 2022


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

--- Comment #6 from johanengelen at weka.io ---
(In reply to Iain Buclaw from comment #5)
> (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".

This depends on the interpretation of "BigEndian". I interpret it as byte
endianness, where BigEndian means: each byte is little endian (`value & 0x1`
giving the value of the LSB) and bytes are packed big endian (`array[0]` giving
the most significant byte). Like wikipedia's interpretation:
https://en.wikipedia.org/wiki/Endianness#Overview

I agree that clarification in the bitfields documentation is needed on the
matter.

--


More information about the Digitalmars-d-bugs mailing list