This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ choosing wrong function for Xt callback
- To: Alexandre Oliva <oliva at lsd dot ic dot unicamp dot br>
- Subject: Re: g++ choosing wrong function for Xt callback
- From: Gary Beckmann <gary at radionics dot com>
- Date: Thu, 13 Jan 2000 16:27:08 -0500
- Cc: Gary Beckmann <gary at radionics dot com>, egcs-bugs at egcs dot cygnus dot com
- References: <14459.39828.510347.272363@rules><00Jan12.113909est.14347@ed209.radionics.com><or4schiyiy.fsf@garnize.lsd.ic.unicamp.br>
>>>>> Alexandre Oliva writes:
oliva> Can you please post a simpler code snippet that demonstrates the
oliva> problem? It seems that your message has lost some headers somehow,
oliva> because the attachment doesn't show up as such at my end.
Sorry, it is a simple snippet, I was just trying to include all of the
intermediate files. This doesn't do anything (no main, etc.) but does
demonstrate the warning....
g++ -c wrong-func.cxx
======================= wrong-func.cxx =======================
#include <stdlib.h>
#include <X11/Intrinsic.h>
class tog_c
{
public:
virtual void create (Widget parent, char *widget_name = NULL);
static void myHack( Widget, XtPointer, XtPointer );
virtual void myHack( Widget, XtPointer );
protected:
Widget tog;
};
void tog_c::create (Widget parent, char *widget_name)
{
Arg al[64]; /* Arg List */
register int ac = 0; /* Arg Count */
if ( !widget_name )
widget_name = "tog";
XtAddCallback (tog, "ValueChanged", myHack, (XtPointer) this);
}
void tog_c::myHack( Widget widget, XtPointer client_data, XtPointer call_data )
{
tog_c * instance = (tog_c *) client_data;
instance->myHack ( widget, call_data );
}
=================== end of wrong-func.cxx ====================
There are two ways to get this to work:
- If you reverse the order of the function declaration in the class,
then correct function is chosen. That is, the decl reads
virtual void myHack( Widget, XtPointer );
static void myHack( Widget, XtPointer, XtPointer );
- If qualify the function with the class name, then correct function
is chosen, as in:
XtAddCallback (tog, "ValueChanged", tog_c::myHack, (XtPointer) this);
Version info (so that it's all in the same place).
> g++ --version
egcs-2.91.66
> uname -a
Linux galileo 2.2.5-15 #1 Mon Apr 19 23:00:46 EDT 1999 i686 unknown
Thanks for taking the time to look at this.
----------------------------------------------------------------------
Gary Beckmann | e-mail: gbeckmann@radionics.com
RADIONICS | or: gary.beckmann@acm.org
22 Terry Ave. | telephone: (781)238-0600
Burlington, MA 01803 | fax: (781)238-0606
USA |
----------------------------------------------------------------------