GP32 Function Pointers (for Events)


pea

developer
Joined
Oct 3, 2004
Messages
1,089
Age
45
Location
New Zealand
Website
www.projectitis.com
Hi all,

I am implementing some events (callbacks) into my GPDesktop widgets now, and have come across a problem that I daresay has a simple solution.

The problem is that one of the inputs into my callback function is a struct that I declare later on, and it doesn't like it because the struct doesn't exist yet. The problem is that I can't move the declaration of the struct above the declaration of the callback function either, because the struct itself contains one of these callbacks!!

example:
Code:
typedef void (*eGPD_onButtonPress)( tGPD_widget*, unsigned short, unsigned short, char, char);
typedef void (*eGPD_onMouseIn)( tGPD_widget* );
typedef void (*eGPD_onMouseOut)( tGPD_widget* );

typedef struct tGPD_widget{
	char type;
	void *object;
	unsigned short x;
	unsigned short y;
	tGPD_list *children;
	struct tGPD_widget *parent;
	char redraw;
	eGPD_onMouseIn onMouseIn;
	eGPD_onMouseOut onMouseOut; 
}tGPD_widget;

As you can see, tGPD_widget contains two events/callbacks (so far) which also have tGPD_widgets as inputs.

How do I properly define these?
 
Got it... the best solution, which doesn't give any warnings about scope etc, is:

Code:
typedef struct tGPD_widget* pGPD_widget;
typedef void (*eGPD_onButtonPress)( pGPD_widget, unsigned short, unsigned short, char, char);
typedef void (*eGPD_onMouseIn)( pGPD_widget );
typedef void (*eGPD_onMouseOut)( pGPD_widget );
 
Back
Top