【问题标题】:Struct with a pointer to its own type in ctypes在 ctypes 中带有指向其自身类型的指针的结构
【发布时间】:2009-02-12 21:47:04
【问题描述】:

我正在尝试使用 ctypes 映射结构定义:

struct attrl {
               struct attrl *next;
               char         *name;
               char         *resource;
               char         *value;
           };

我不确定如何处理 ctypes 映射中结构的“下一个”字段。如下定义:

class attrl(Structure):
    _fields_ = [
        ("next", attrl),
        ("name", c_char_p), 
        ("resource", c_char_p), 
        ("value", c_char_p)
    ]

结果:

NameError: name 'attrl' is not defined

【问题讨论】:

    标签: python ctypes


    【解决方案1】:

    您需要相当于前向声明as described here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多