Is Python ctypes.c_long 64-bit on 64-bit systems?

In C, the length is 64 bits on a 64-bit system. Is this reflected in the Python ctypes module?

+7
python 64bit ctypes
source share
4 answers

The size of long depends on the memory model . On Windows (LLP64) it is 32-bit, on UNIX (LP64) it is 64-bit.

If you need a 64 bit integer, use c_int64 .

If you need an integer pointer size, use c_void_p ("The value is represented as an integer").

+10
source share

Not really.

On a 64-bit Windows system, the length is 32 bits.

 Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> ctypes.c_long(2**31) c_long(-2147483648) >>> ctypes.c_long(2**31+1) c_long(-2147483647) >>> ctypes.c_long(2**31-1) c_long(2147483647) >>> 

See What is the bit size in 64-bit Windows?

+4
source share

If C long is 64-bit (for example, it is on LP64 and ILP64 systems, on almost any 64-bit system other than Windows), then this means ctypes.c_long . If the length of C is not 64-bit (for example, on LLP64 systems such as 64-bit Windows), then ctypes.c_long is not there either.

+2
source share

Yes.

 >>> ctypes.c_long(2**50) c_long(1125899906842624) >>> ctypes.c_long(2**64) c_long(0) >>> ctypes.c_long(2**63) c_long(-9223372036854775808) 
+1
source share

All Articles