Re: [gtk-list] Re: types checking signal/callback functions revisited
- From: Marius Vollmer <mvo zagadka ping de>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: types checking signal/callback functions revisited
- Date: 26 Jun 1998 23:36:11 +0200
Owen Taylor <otaylor@gtk.org> writes:
> Bil Wendling <wendling@ganymede.isdn.uiuc.edu> writes:
>
> > 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.
>
> I'm pretty sure you are wrong about this - at least for all
> platforms worth considering in the context of GTK+. The C standard
> requires (if I remember correctly) that any pointer type will
> survive a round-trip cast to a different pointer type.
I wouldn't be surprised if the C standard only guarantees this if the
compiler actually sees the cast. This is not the case when you invoke
a function thru a pointer that the compiler thinks is pointing to a
function with a different signature. That is
void callback (GtkWidget *w, gpointer p)
{
GtkWhatever *we = p; // visible cast from void* to GtkWhatever*
while
void callback (GtkWidget *w, GtkWhatever *p);
...
gpointer p;
((void (*)(GtkWidget *w, gpointer))callback) (w, p); // invisible
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]