指针在 Python 中并不常见, 无论是 var 声明类型 。 在 Python 中, 我非常适合这样做 。
C++ :
...a function
flt32 f;
int32 sign, exp, man, *tms;
tms = (int *) &f;
...(operations)
*tms = sign | exp | man;
return (f);
如您所见, tms
指向 f
数据,但仅指向 unt
中
部分(btw,此函数运作良好)。
用这种类型,我可以用 Python 的指针:
from ctypes import *
f = c_float(12.3)
tms = pointer(f) # tms should be: tms = c_int32(value)
print tms.contents.value #12.3000001907
The problem here is that tms
becomes instantly the type of f
, so both variables are float (tms
should be tms = c_int32(a_value))
.
It is possible to use a pointer that just matches the int
value from a float
variable in Python?