[issue6924] struct.unpack weird behavior with "bi" (byte then integer)
Mark Dickinson
report at bugs.python.org
Thu Sep 17 00:05:55 CEST 2009
Mark Dickinson <dickinsm at gmail.com> added the comment:
I think this is expected behaviour: the key point is that structs can
include padding bytes. From the documentation:
"By default, C numbers are represented in the machine’s native format and
byte order, and properly aligned by skipping pad bytes if necessary
(according to the rules used by the C compiler)."
'Native' struct formats include padding, while 'standard' formats don't.
So a native struct with format 'BI' has one byte for the 'B', followed by
3 padding bytes, followed by four bytes for the 'I'. This exactly matches
the way a C struct of the form {char c; int x;} would be organized in
memory on that machine.
----------
assignee: -> marketdickinson
nosy: +marketdickinson
resolution: -> works for me
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6924>
_______________________________________
More information about the Python-bugs-list
mailing list