【问题标题】:Convert python int into int16_t type将python int转换为int16_t类型
【发布时间】:2016-06-07 12:17:26
【问题描述】:

我知道 python int 可以使用 ctypes 转换成 c int 类型。
但是如何将 python int 转换成 int16_t 类型呢?

我试过了:

import ctypes as ct
my_c_number = ct.c_int16_t(1)
#Apparently ctypes library does not have c_int16_t attribute.

【问题讨论】:

  • int16_t 或 uint16_t?并阅读文档,IIRC,有一个尺寸对应表。
  • 要么。是的,但它没有提到任何 _t 类型甚至 int 大小类型。

标签: python c python-2.7 types type-conversion


【解决方案1】:

ctypes.c_int16 怎么样?如果您正在寻找它,还支持ctypes.c_uint16。

文档:
https://docs.python.org/2/library/ctypes.html#ctypes.c_int16 和
https://docs.python.org/2/library/ctypes.html#ctypes.c_uint16

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-20
    • 2016-03-12
    • 2017-11-05
    • 2017-07-28
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    • 2016-04-21
    相关资源
    最近更新 更多