C/C++ function signatures are written with C/C++ types, like "int" or "double" or "uint32_t". All of these have corresponding ctypes equivalents, so normally you do not care about the number of bits.
That said...
import os
print os.sysconf('SC_CHAR_BIT')
...is about as close as you will get, I think. Does not work on non-Unix platforms. And as tMC points out in the comments, it does not even work on all Unix platforms; I believe it is a GNU extension.
[update]
Actually, the POSIX spec appears to mandate CHAR_BIT == 8. So on any system that supports the SC_CHAR_BIT sysconf selector, you do not actually need it :-).
发布评论
评论(1)
C/C++ 函数签名是用 C/C++ 类型编写的,例如“int”、“double”或“uint32_t”。所有这些都有相应的 ctypes 等效项,因此通常您不关心位数。
这就是说……
我想这已经是你所能得到的最接近的了。不适用于非 Unix 平台。正如 tMC 在评论中指出的那样,它甚至不能在所有 Unix 平台上运行;我相信它是一个 GNU 扩展。
[更新]
实际上,POSIX 规范似乎强制要求 CHAR_BIT = = 8. 因此,在任何支持 SC_CHAR_BIT sysconf 选择器的系统上,您实际上并不需要它:-)。
C/C++ function signatures are written with C/C++ types, like "int" or "double" or "uint32_t". All of these have corresponding ctypes equivalents, so normally you do not care about the number of bits.
That said...
...is about as close as you will get, I think. Does not work on non-Unix platforms. And as tMC points out in the comments, it does not even work on all Unix platforms; I believe it is a GNU extension.
[update]
Actually, the POSIX spec appears to mandate CHAR_BIT == 8. So on any system that supports the SC_CHAR_BIT sysconf selector, you do not actually need it :-).