struct curiosity

pjcoup pjcoup at gmail.com
Thu Oct 15 20:07:04 CEST 2009


Hello,

I was fooling around with python's struct lib, looking on how we'd
unpack some data.  I was a little confused by its behavior:
Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.calcsize('BhhhhB')
11
>>> struct.calcsize('@BhhhhB')
11
>>> struct.calcsize('<BhhhhB')
10
>>> struct.calcsize('>BhhhhB')
10

I would have expected calcsize('BhhhhB') to be either 10 or 12
(padding), but 11?
Is there a simple explanation of what is going on here?  Just a
curiosity.
This is on a x86_64, but have seen the same on i686.  Ideas?

Thanks.
Pete



More information about the Python-list mailing list