Structures are similar to Python classes, except they do not contain any methods. They are the next element that you convert from C to Pyrex. To convert the structure:
typedef struct with
cdef struct,}) to after the
struct,
; from the end of each line, and
{} blocking with a
: and indenting.Structures will look something like the following (from the
CUPS cups.h
file).
typedef struct
{
char *name;
char *value;
} cups_option_t;
This is a structure, called cups_option_t, that holds
two elements: name and value.
The Pyrex version looks similar, including the types!
cdef struct cups_option_t: char *name char *value
Structures can also hold other structure, just like C. For example:
cdef struct cups_dest_t: char *name char *instance int is_default int num_options cups_option_t *options
The options value of the above structure holds a
pointer to the cups_option_t structure we declared
earlier.
You may want to try and
compile the two structures
above, linking against the cups library.
Some structures are external to the C header-file.
To declare these structures you use the extern
keyword.
Consider the following example, taken from
xosd.h.
typedef struct xosd xosd;
In Pyrex it would look like the following.
cdef extern struct xosd
| Previous | Contents | Next |