如何制作所有Python3号码CTYPE.C_INT32?
我正在尝试使用python3复制C程序行为,并反复将所有数字投入到CTYPES.C_INT32变得丑陋。
有什么办法可以默认python的int是ctypes.c_int32的实例?
编辑: 我想在多个C_INT32对象(例如XOR-ing和and-ing)之间执行算术操作,但是如果不添加.Value
在每个C_TYPE INT对象后面,我就无法执行此操作。我想看看是否可以以某种方式覆盖默认的python int
对象与ctypes中的c_int32
更相似。
I am trying to replicate C program behaviours using Python3 and repeatedly casting all numbers to ctypes.c_int32 get ugly real fast.
Is there any way I could default Python's int to be an instance of ctypes.c_int32?
Edit:
I would like to perform arithmetic operations between multiple c_int32 objects (e.g. xor-ing and and-ing), but I can't do this without adding .value
behind every c_type int object. I want to see if I can somehow override the default python int
object to behave more similarly to c_int32
in ctypes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在Python 3中做您想做的事。
如果您只想将数学结果限制为签名的INT32结果
ctypes
不需要。以下截断n
降低32位,然后调整符号位:You can't do what you want in Python 3.
int
in Python 2.3 and earlier (before int/long integration) worked they way I think you want.If you just want to constrain math results to signed int32 results
ctypes
isn't needed. The following truncatesn
to the lower 32 bits, then adjusts for the sign bit: