Re: pointer casts



Owen Taylor wrote:

Miroslaw Dobrzanski-Neumann <mne mosaic-ag com> writes:

Hi,

Compiling gclosure.c with DEC C V5.6-082 compiler I get the warnings listed
below (the same warnings are produced by the ibm xlc compiler). The problem is
that pointer to void is not the same as pointer to function. You can safe cast
data pointer but casting function pointer in i.e. pascal calling convention and
calling it afterwards as different ones produce a desaster.

After having take a look at the data types of the two sides of the assignemt I
wonder how it works.

gclosure.c:107 closure->marshal = (gpointer) ndata->notify;


GCC has a non-standard extension that allows implicit casts betweeen (void *)
and any function pointers.

Unfortunately, this has led to people doing bad stuff like this and also to
some messed up prototypes like:

gulong	 g_signal_handler_find		      (gpointer		  instance,
					       GSignalMatchType	  mask,
					       guint		  signal_id,
					       GQuark		  detail,
					       GClosure		 *closure,
					       gpointer		  func,
					       gpointer		  data);

That we just have to live with at this point.

I've given Erwann the go ahead to commit his patch in #73898 which should fix
all of these sorts of warnings in GLib.

Would GCC's -Wbad-function-cast warning flag warn about these sort of bad casts?

James.

--
Email: james daa com au
WWW:   http://www.daa.com.au/~james/






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