Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Python's ctypes.c_long 64 bit on 64 bit systems?

In C, long is 64 bit on a 64 bit system. Is this reflected in Python's ctypes module?

like image 277
Matt Joiner Avatar asked Jul 24 '10 04:07

Matt Joiner


2 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 a pointer-sized integer, use c_void_p (“The value is represented as integer”).

like image 133
kennytm Avatar answered Sep 25 '22 23:09

kennytm


Actually no.

On a Windows 64-bit system, long 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 of long on 64-bit Windows?

like image 42
casevh Avatar answered Sep 23 '22 23:09

casevh