C Library Catch-22

I haven't run across this kind of problem before, and I'm not sure how best to resolve it...

I have a struct that is used as an object handle (this is C, not C++):

typedef struct {
  int  a;
  int  b;
  int  c;
  callback_t  *callback;
}  Widget;

The "callback" element is a (somewhat) dynamic array of callback function pointers, defined by the following typedef:

typedef void (*callback_t)(Widget *w, uint8_t event);

The "object" is created like this:

Widget  widget_init (int a, int b, int c) {
    Widget  *tmp;
    tmp = malloc(sizeof(Widget));
    tmp->callback = malloc(sizeof(callback_t) * WIDGET_EVENT_COUNT);
    return tmp;
}

void main () {
    Widget  *my_widget = widget_init(1, 2, 3);
    ...
}

The point is to be able to register user-defined callback functions, and have the library call them on particular events:

void my_callback (Widget *w, uint8_t event) {
    if (event == WIDGET_EVENT_PET_CAT_BACKWARDS) {
        // The cat has been pet from tail to head
        // All that can be done is to simply increment w->a
        // and hope for the best.
        w->a++;
    }
}

void widget_setcallback (Widget *w, uint8_t event, callback_t callback) {
    w->callback[event] = callback;
}

void main () {
    ....
    widget_setcallback(my_widget, WIDGET_EVENT_PET_CAT_BACKWARDS, my_callback);
    ....
}

The problem I'm having is that the object struct defines an element that is an array of callbacks, since they are specific to this object instance... but... the callback definition includes the object type as a parameter. Since they depend on each other, neither can be defined first without referencing a definition that doesn't exist yet.

typedef struct {
  int  a;
  int  b;
  int  c;
  callback_t  *callback;  // Requires callback_t to be defined
}  Widget;

// Requires Widget to be defined
typedef void (*callback_t)(Widget *w, uint8_t event);

I have neither a chicken nor an egg. How to fix? :-\

typedef struct tagWidget;

typedef void (*callback_t)(struct tagWidget *w, uint8_t event);

typedef struct tagWidget {
  int  a;
  int  b;
  int  c;
  callback_t  *callback;  // Requires callback_t to be defined
}  Widget;

Seems to do the trick. Thanks man!

You are welcome. And enjoy your new world view brought to you by tagged structures.