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



On 24 Jun 1998, Owen Taylor wrote:
}
}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.
}
}You can get into trouble with alignment if you try to use
}a pointer to one type as a pointer to a type of a different
}alignment, and then try to use it that way. But that is
}a different issue entirely.
}
Hi Owen,

Certainly a pointer can survive a cast to/from a void *. I think the
problem comes from the fact that the void * type is buried inside of the
function prototype, thus changing the type of the function altogether, in
which case your second statement might come into play.

You are most likely correct, however, that this situation won't adversely
affect most platforms GTK will be used on. And I can't quote you chapter
and verse on exactly why the above is bad, though I will try to find out
if you'd like to pursue this (Um...you have nothing else to do, right?
:-). 

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



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