Kamil Kisiel
Kamil Kisiel

Reputation: 20451

Struct with a pointer to its own type in ctypes

I'm trying to map a struct definition using 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. 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

Upvotes: 4

Views: 1005

Answers (1)

Morendil
Morendil

Reputation: 3968

You need the equivalent of a forward declaration, as described here.

Upvotes: 4

Related Questions