byref(n)返回的相当于C的指针右值&n,本身没有被分配空间:
>>> from ctypes import *
>>> n = c_int(0)
>>> p = byref(n)
>>> pp = byref(p)
Traceback (most recent call last):
File "", line 1, in
pp = byref(p)
TypeError: byref() argument must be a ctypes instance, not 'CArgObject'
pointer返回的相当于指针左值T* p=&n,可以改变,可以取地址:
>>> from ctypes import *
>>> n = c_int(0)
>>> q = pointer(n)
>>> q.contents = c_int(1)
>>> qq = byref(q)
>>> dir(qq)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_obj']
>>> type(qq)
>>> q
<__main__.LP_c_long object at 0x010AD210>
>>> q.contens
>>> q.contents
c_long(1)
对于T**参数,通常你得构造一个pointer,然后byref传进去
PS: addressof返回一个Python整数,不能直接传给C那边