This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g++ choosing wrong function for Xt callback


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]