Can you cast a pointer to a function of this type:
void (*one)(int a)
to one of this type:
void (*two)(int a, int b)
and then safely call the specified function with the additional arguments (s) that it was selected to accept? I believed that such a thing was illegal, that both types of functions should be compatible. (The value of the same prototype is the same return value, the same list of parameters.) But this is exactly what this GTK + code bit does (taken from here ):
g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(window));
If you look at the signal βclickedβ (or just look at other examples of its use from the first link), you will see that its handlers should be declared as follows:
void user_function(GtkButton *button, gpointer user_data);
When you register a handler with g_signal_connect_swapped (), the arguments of the widget pointer and data pointer are reversed, so the declaration should look like this:
void user_function(gpointer user_data, GtkButton *button);
Here is the problem. The gtk_widget_destroy () function registered as a callback is prototyped as follows:
void gtk_widget_destroy(GtkWidget *widget);
take only one argument. Presumably, since the data pointer (GtkWindow) and the pointer to the alarm widget (GtkButton) are swapped, the only argument that it gets is the window pointer, and the button pointer that will be passed after will be silently ignored, Some Googling included similar examples, even registering functions like gtk_main_quit () that take no arguments at all.
Do I think this is a violation of the standards? Ask GTK + developers to find legit magic to make it work?