首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python怎么映射 包含union的结构体啊

2013-06-25 
python如何映射 包含union的结构体啊?求解决方案啊!比如结构体:struct a{int arg0union{int bint cint

python如何映射 包含union的结构体啊?
求解决方案啊!
比如结构体:
struct a{
   int arg0;
   union{
      int b;int c;int d;
   }
}
用ctypes该如何抽象出来?
怎么使用呢?
[解决办法]
不认真看,明明有个范例...

 _anonymous_

    An optional sequence that lists the names of unnamed (anonymous) fields. _anonymous_ must be already defined when _fields_ is assigned, otherwise it will have no effect.

    The fields listed in this variable must be structure or union type fields. ctypes will create descriptors in the structure type that allows to access the nested fields directly, without the need to create the structure or union field.

    Here is an example type (Windows):

    class _U(Union):
        _fields_ = [("lptdesc", POINTER(TYPEDESC)),
                    ("lpadesc", POINTER(ARRAYDESC)),
                    ("hreftype", HREFTYPE)]

    class TYPEDESC(Structure):
        _anonymous_ = ("u",)
        _fields_ = [("u", _U),
                    ("vt", VARTYPE)]

热点排行