How to define a C struct which contain a struct inside a Ctype python

1k views Asked by At

Hi I am learning python and using ctype to embedd 'C' in python. My query is- How to use C stru which again calling a stru inside into cytpe/python.

typedef struct {    
   struct *i, *j; 
   BOOLEAN z; 
} foo;
1

There are 1 answers

1
John Flatness On

It's not entirely clear from your question, but it looks like you're trying to define a struct that contains a pointer to the same type. It's not immediately obvious how you would accomplish this in python, but you basically define your Structure, and then define the _fields_ attribute afterwards.

The ctype docs on python.org have a perfectly on-point example of doing exactly this.

There's also good documentation there on working with structs in general, including nesting one struct type within another, which works a little more obviously.