Harsh Nisar
Harsh Nisar

Reputation: 84

What does struct.calcsize('P') exactly mean?

I stumbled upon this while going through installation instructions of scikit-learn. To check the architecture of your system, whether it is 32 or 64 bit

What does it exactly mean? What does P format specifier mean? How does it differ in a 32 bit system and a 64 bit system.

What happens when I put different specifiers?

Upvotes: 2

Views: 5902

Answers (1)

Dunes
Dunes

Reputation: 40683

struct is a module for packing and unpacking data to and from C representations. P represents void * (a generic pointer). On 32-bit systems a pointer is 4 bytes, and on a 64-bit system a pointer requires 8 bytes. struct.calcsize('P') calculates the number of bytes required to store a single pointer -- returning 4 on a 32-bit system and 8 on a 64-bit system.

Upvotes: 8

Related Questions