user3691223
user3691223

Reputation: 353

Python struct.calcsize doesn't work for QWord

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

Answers (1)

falsetru
falsetru

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

Related Questions