简体   繁体   English

带有指向ctypes中自己类型的指针的struct

[英]Struct with a pointer to its own type in ctypes

I'm trying to map a struct definition using ctypes: 我正在尝试使用ctypes映射结构定义:

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

I'm unsure what to do with the "next" field of the struct in the ctypes mapping. 我不确定如何处理ctypes映射中结构的“next”字段。 A definition like: 定义如下:

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

results in: 结果是:

NameError: name 'attrl' is not defined

您需要等效的前向声明, 如此处所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM