2017-12-18 27 views
1

私はプリミティブフィールド(int、uint8、...)とポインタも含む構造体を持っています。 これらのポインタは、深くネストされた構造を維持するために、異なる構造型の配列を指すことがよくあります。 たとえばCで:ctypesのとPythonでpython ctypes:ポインター変数からポインティング型を取得

struct A 
{ 
int field1; 
int field2; 
struct B *fields3; 
unsigned int countofb; 
} 

struct B 
{ 
    int anotherfield1; 
    int anotherfield2; 
} 

IはAとB は、構造Aの_fields_を反復構造のラッパーを作成Iは第3フィールドfield3に達し、I型LP_struct_BのCTYPE変数を取得します。

質問は、ポインター型にポインターを変換する方法、関数、ctypesの方法はありますか?

私は

a=A() 
st=pointedtype(a.field3) # or also st = pointedtype2(LP_struct_B) 
#desired output: st = struct_B 

おかげ

答えて

1

オクラホマのようなものを必要としています。 私は経験的に答えを見つけました。 変数またはポインタタイプの属性_type_を使用するだけです

a=A() 
print a.fields3._type_ # struct_B 
tipo=type(a.fields3) # tipo=LP_struct_B 
print tipo._type_ # struct_B 
関連する問題