Home > Net >  Ctypes Data type conversion
Ctypes Data type conversion

Time:05-19

I am a ctypes beginner using Python 3.9.7 on Windows,I met a problem ,Examples are as follows

n = c_int(10)
print(n)
>> n = c_long(10)

Why does it become c_long(10) after it is assigned to n

CodePudding user response:

Reproducible on Windows. c_int is an alias for c_long since the size of int and long are both 32-bit on Windows.

Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> n = c_int(10)
>>> print(n)
c_long(10)
>>> c_int
<class 'ctypes.c_long'>
>>> c_long
<class 'ctypes.c_long'>
>>> c_int is c_long       # two names for the same object
True
>>> x = int               # just like making a new name for int
>>> x
<class 'int'>
>>> int
<class 'int'>
  • Related