Andrew Andrew - 5 months ago 37
Python Question

Enums with pointers in struct definitions

I am working on creating access to a dynamic library in python using the ctypes module. While duplicating some of the tydef'd structures in my python implementation I came across a bit of code that has me stumped as to what is happening. Basically what I have is

enum foo {

typedef struct barStruct bar;

struct barStruct{
enum foo (*lem)();
enum foo (*baz)(bar *next);

in a header file.

I am trying to understand the two enum calls in the struct definition. I thought that the first one was creating a pointer called
which has to point to values contained in the enumeration (so I essentially ignored the open/close parenthesis at the end). When I noticed the second one, with another pointer in the parenthesis, then I got really confused as to what is going on, and doubted my guess as to what the first one meant.

I apologize if this question already has an answer (which I'm sure it does) but unfortunately I cannot think of how to effectively search for what I need.


Those aren't "enum calls", those are declaring two members in the structure, members that are pointers to functions.

For example

enum foo (*lem)();

declares a structure member variable lem that is a pointer to a function taking an indeterminate number of arguments, and returns a foo enumeration.