Bug in struct.calcsize() ?
Andrew Henshaw
andrew.henshaw at gtri.gatech.edu
Fri Apr 9 07:15:16 EDT 2004
James Lamanna wrote:
> Noticed this under 2.3.3:
>
> struct.calcsize('H') => 2
> struct.calcsize('BBB') => 3
> struct.calcsize('BBBH') => 6
>
> Umm, shouldn't 'BBBH' return 5?
>
> Please CC me for I am not subscribed.
>
I'll also post here (for the benefit of others that might google for this
question).
In the struct documentation, there is a table for byte order and alignment.
Providing one of the characters '@=><!' as the first character of your
string specifies the byte order and alignment behavior. Since your string
doesn't specify one, then native byte order and alignment are assumed. In
this case, your C compiler aligns 16-bit ints to a 16-bit boundary. To
pack without padding, use '=' as the first character.
struct.calcsize('=BBBH') => 5
--
Andy
More information about the Python-list
mailing list