Re: pointer casts



James Henstridge <james daa com au> writes:

> 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?

I think it's something different. What, reading the docs, this seems
like it would warn about is explicit casts between non-function
pointers and function pointers, which, I believe, are undefined in
the C standard though they do typically work. 

[and better work, considering the the API we are stuck with now]

I suspect -ansi and/or -pedantic would probably complain about the GCC
"extension" to allow omitting the cast for a cast from void * to function
pointer or vice versa.

Regards,
                                        Owen



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