Re: pointer casts



On Wed, Mar 13, 2002 at 11:50:15PM +0800, James Henstridge wrote:
> 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?
no, void * is considered (by gcc version 2.95.3) to be an universal datatype

the code (stored in x.c) goes thru gcc -Wbad-function-cast -c x.c without any
warning

typedef void (* tf1) (int);
typedef void (* tf2) (void *);
tf2 cast_func (tf1 f) { return (void *) f; }

Regards,
-- 
Miroslaw Dobrzanski-Neumann

MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne mosaic-ag com




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