如何创建指向正在定义的结构的指针?

2024-09-29 21:32:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在围绕^{}编写一个Python包装器。接口使用struct ifaddrs类型,其第一个字段是指向另一个struct ifaddrs的指针。在

struct ifaddrs {
    struct ifaddrs *ifa_next;   /* Pointer to the next structure.  */
    ... /* SNIP!!11 */
};

但是,在Python中表示:

^{pr2}$

给出此错误:

matt@stanley:~/src/pydlnadms$ ./getifaddrs.py 
Traceback (most recent call last):
  File "./getifaddrs.py", line 58, in <module>
    class struct_ifaddrs(Structure):
  File "./getifaddrs.py", line 61, in struct_ifaddrs
    ('ifa_next', POINTER(struct_ifaddrs)),
NameError: name 'struct_ifaddrs' is not defined

在完成类定义之前,struct_ifaddrs不会绑定到当前作用域。当然,作为指针类型,很明显,struct_ifaddrs的定义在声明过程中并不需要,就像在C中一样,但是在以后的使用中需要取消对该类型的定义。我该怎么办?在


Tags: toinpy类型定义linestructfile

热门问题