Rajesh
Rajesh

Reputation: 11

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

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;

Upvotes: 0

Views: 1012

Answers (1)

John Flatness
John Flatness

Reputation: 33809

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.

Upvotes: 1

Related Questions