8
  1. API が 64 ビット型を想定している場合、バイト数を返すctypes場合、型にそのビット数があることを確認するにはどうすればよいですか?sizeof
  2. 現在のプラットフォームで各バイトに含まれるビット数を知るにはどうすればよいですか?
  3. Python ではどこでCHAR_BIT定義されていますか?
4

1 に答える 1

6

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 :-).

于 2011-06-03T05:16:56.343 に答える