struct containing a function pointer with itself as a return type in C

c, function-pointers, struct

Solution

Your struct needs needs to be defined like this:

typedef struct event  // <<< note the `event` tag here
{
    lamp *lamp;
    unsigned char a;
    unsigned char b;
    unsigned char c;
    unsigned char d;
    unsigned char e;
    void (*func)(struct event *);
} event;              // <<< you can still keep `event` as a typedef
                      //     which is equivalent to `struct event`

Problem

Got the following data struct: ``` typedef struct { lamp *lamp; unsigned char a; unsigned char b; unsigned char c; unsigned char d; unsigned char e; void (*func)(struct event *); } event; ``` The last line inside the struct is supposed to be a pointer to a function with return type void with pointer to an event as an argument such as: ``` void function(event *evt); ``` Though, I get the following warning message: "its scope is only this definition or declaration, which is probably not what you want". Is this right or wrong?

Original source