Martin Panter added the comment:

It would be helpful if you could trim down your example code a bit. Without 
studying the whole file, it is hard to see exactly what order you are seeing 
and what order you expect, since there are two versions with different orders 
in the code.

My understanding of the “ctypes” module is that it is for interacting with the 
local OS, ABI, compiler, etc, which could use various layouts depending on the 
platform. According to the Linux x86-64 ABI 
<http:/www.x86-64.org/documentation/abi.pdf>, page 14, “bit-fields are 
allocated from right to left”, which I interpret to mean from least-significant 
to most-significant bit. Not so sure about Windows, but 
<https://msdn.microsoft.com/en-us/library/yszfawxh.aspx> suggests a similar 
story (LSB first). This behaviour agrees with my experiments on Linux and Wine:

>>> class Bitfield(Structure):
...     _fields_ = (("a", c_uint8, 4), ("b", c_uint8, 4))
... 
>>> bytes(Bitfield(0xA, 0xB))
b'\xba'

Does this agree with what you expect? Otherwise, what leads you to expect 
something different?

Also:
* bytes(saej1939_message_id) should copy the bytes directly; no need for a 
union.
* struct.unpack() should also accept a “ctypes” object directly; no need for 
the copy.

----------
nosy: +martin.panter

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to