Re: [gtk-list] Re: types checking signal/callback functions revisited



On Wed, 24 Jun 1998, Steve Hosgood wrote:

}> 
}> I've been thinking about the problem of checking the types expected
}> by callback functions [...] 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 [....]
}> 
}> 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?
}> 
}
}I swapped a few ideas along these lines with Owen(was it?) and some of the
}other gurus a month or so ago. They seemed to think that there was a
}problem in that everyone (except me) likes to misdeclare the callback
}functions to something like:
}
}	void callback( GtkWidget *w, GtkWhatever *x )
}	{
}
}
}..rather than what *should* be done, i.e:
}
}	void callback( GtkWidget *w,  gpointer param )
}	{
}		GtkWhatever *x = param;
}
}
}
}Strict type-checking would stop this practice. I say "good!", others
}disagree. I've been blown up by some callback parameter mismatches
}in my time. I also note that most beginners like me waste a fair bit
}of list-bandwidth asking the same questions caused by such problems
}that they too are having.
}
}So I say, "go for strong type-checking". It'll save us all time and
}trouble in the end.
}	
I had a similar situation come up in a project I'm working on right now.
Basically, using the pointer to the function

	void callback(GtkWidget *, GtkWhatever *)

when the program expects you to use

	void callback(GtkWidget *, gpointer)

is not a Good Thing (tm). They are two different types and there is no
guarantee that the compiler will do the right thing with them. In other
words, this may break on some platforms in undefined ways.

|| Bil Wendling			wendling@ncsa.uiuc.edu
|| Research Programmer



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