Reputation: 353
I cannot find out why this doesn't work. I want to read one integer (double word) and 4 quadwords using struct modul. This represens 4 + 4 * 8 = 36 bytes, but python gives me this:
>>> import struct
>>> struct.calcsize("I4Q")
40
Does anyone know why? Thanks a lot...
Upvotes: 1
Views: 288
Reputation: 368914
According to the documentation: Byte Order, Size, and Alignment:
By default, C types 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).
>>> struct.calcsize("I4Q")
40
>>> struct.calcsize("@I4Q")
40
If you specify >
, =
, <
, !
, native alignment is not used:
>>> struct.calcsize(">I4Q")
36
>>> struct.calcsize("=I4Q")
36
>>> struct.calcsize("<I4Q")
36
>>> struct.calcsize("!I4Q")
36
Upvotes: 1