types checking signal/callback functions revisited




I've been thinking about the problem of checking the types expected
by callback functions, and those actually declared by the function
itself. For example, the declaration of the function used in a call
to:

gint gdk_input_add( gint              source,
                    GdkInputCondition condition,
                    GdkInputFunction  function,
                    gpointer          data );

should be declared like:

void input_callback( gpointer          data,
                     gint              source, 
                     GdkInputCondition condition );

but there are no compile- or run-time checks that this is done
correctly.

Now, the only way I can think of actually getting the compiler to
check this is at function declaration. So, if we defined a macro
like:

#define GTK_INPUT_FUNC(f) void f( gpointer, gint, GdkInputCondition )

we could then forward declare our callback function with:

GTK_INPUT_FUNC(input_callback);

which would allow the compiler to perform a check that the
declaration and the definition match.

Similar things can be done with all the signal callbacks, and still 
allow us to keep the simplicity of using gtk_signal_connect.

Any thoughts or better ways of doing this?

Thanks

Tony


---
E-Mail: trog@gtk.org
If I could drop dead right now, I'd be the happiest man alive!
		-- Samuel Goldwyn

Go Bezerk! http://www.gtk.org/~trog



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]