g++ choosing wrong function for Xt callback (1/14)

Gary Beckmann gary@radionics.com
Tue Jan 11 13:30:00 GMT 2000


MIME-Version: 1.0
Date: Tue, 11 Jan 2000 16:13:42 -0500 (EST)
From: Gary Beckmann <gary@radionics.com>
To: egcs-bugs@egcs.cygnus.com
Subject: g++ choosing wrong function for Xt callback
X-Mailer: VM 6.43 under 20.4 "Emerald" XEmacs  Lucid
Message-ID: <14459.39828.510347.272363@rules>
Content-Type: text/plain; charset=US-ASCII


--d+E7n+rQK+
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Using the convention put forth by Young we use two functions in a
class, one is declared static with the three arguments that Xt expects 
as the signature for a callback funtion, this function when called
uses the client data pointer to obtain a "this" pointer and calls the
object specific method, which has been declared as a virtual.  

The compiler is using the wrong function, even issuing a warning that
it is forcing a cast and a "&" instead of using the static member
function which is in the declaration.

Output from compilation:
>  g++ -v --save-temps wrong-func.cxx 
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ wrong-func.cxx wrong-func.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++-2
 /usr/local/include
 /usr/i386-redhat-linux/include
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1plus wrong-func.ii -quiet -dumpbase wrong-func.cc -version -o wrong-func.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
wrong-func.cxx: In method `void tog_c::create(struct _WidgetRec *, char * = 0)':
wrong-func.cxx:22: warning: implicit declaration of function `int XmCreateToggleButton(...)'
wrong-func.cxx:22: warning: assignment to `_WidgetRec *' from `int' lacks a cast
wrong-func.cxx:24: `XmNvalueChangedCallback' undeclared (first use this function)
wrong-func.cxx:24: (Each undeclared identifier is reported only once
wrong-func.cxx:24: for each function it appears in.)


The source code, and output from the "--save-temps" are attached.

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

--d+E7n+rQK+
Content-Type: text/plain
Content-Description: source code
Content-Disposition: inline;
	filename="wrong-func.cxx"
Content-Transfer-Encoding: 7bit

#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";

	tog = XmCreateToggleButton ( parent, widget_name, al, ac );

	XtAddCallback (tog, XmNvalueChangedCallback, 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 );
}


--d+E7n+rQK+
Content-Type: text/plain
Content-Description: temp file from compilation
Content-Disposition: inline;
	filename="wrong-func.ii"
Content-Transfer-Encoding: 7bit

# 1 "wrong-func.cxx"
# 1 "/usr/include/stdlib.h" 1 3
 

















 





# 1 "/usr/include/features.h" 1 3
 




















 


























































 



















 





 



 







 
# 137 "/usr/include/features.h" 3


 









 





 



























# 195 "/usr/include/features.h" 3


































 



 








 




 

# 1 "/usr/include/sys/cdefs.h" 1 3
 




















 




 





 








 




# 71 "/usr/include/sys/cdefs.h" 3


 







 



# 103 "/usr/include/sys/cdefs.h" 3



 








 















 








 








 









 







# 249 "/usr/include/features.h" 2 3


 








 





 

 








# 1 "/usr/include/gnu/stubs.h" 1 3
 




































# 277 "/usr/include/features.h" 2 3




# 25 "/usr/include/stdlib.h" 2 3


 





# 1 "/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h" 1 3






 


# 19 "/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h" 3



 


 





 


# 61 "/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h" 3


 





 


















 





 

 

# 131 "/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h" 3


 

 


































typedef unsigned int size_t;






















 




 





























 












































# 283 "/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h" 3


 

 

# 317 "/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/stddef.h" 3




 





















# 33 "/usr/include/stdlib.h" 2 3


extern "C" { 




 
typedef struct
  {
    int quot;			 
    int rem;			 
  } div_t;

 

typedef struct
  {
    long int quot;		 
    long int rem;		 
  } ldiv_t;



# 65 "/usr/include/stdlib.h" 3



 



 





 

extern size_t __ctype_get_mb_cur_max  (void)  throw ()  ;


 
extern double atof  (__const char *__nptr)  throw ()  ;
 
extern int atoi  (__const char *__nptr)  throw ()  ;
 
extern long int atol  (__const char *__nptr)  throw ()  ;


 
__extension__ extern long long int atoll  (__const char *__nptr)  throw ()  ;


 
extern double strtod  (__const char *   __nptr,
			   char **   __endptr)  throw ()  ;










 
extern long int strtol  (__const char *   __nptr,
			     char **   __endptr, int __base)  throw ()  ;
 
extern unsigned long int strtoul  (__const char *   __nptr,
				       char **   __endptr,
				       int __base)  throw ()  ;


 
__extension__
extern long long int strtoq  (__const char *   __nptr,
				  char **   __endptr, int __base)  throw ()  ;
 
__extension__
extern unsigned long long int strtouq  (__const char *   __nptr,
					    char **   __endptr,
					    int __base)  throw ()  ;



 

 
__extension__
extern long long int strtoll  (__const char *   __nptr,
				   char **   __endptr, int __base)  throw ()  ;
 
__extension__
extern unsigned long long int strtoull  (__const char *   __nptr,
					     char **   __endptr,
					     int __base)  throw ()  ;



# 190 "/usr/include/stdlib.h" 3



 


extern double __strtod_internal  (__const char *   __nptr,
				      char **   __endptr,
				      int __group)  throw ()  ;
extern float __strtof_internal  (__const char *   __nptr,
				     char **   __endptr, int __group)  throw ()  ;
extern long double  __strtold_internal  (__const char *
						  __nptr,
						char **   __endptr,
						int __group)  throw ()  ;

extern long int __strtol_internal  (__const char *   __nptr,
					char **   __endptr,
					int __base, int __group)  throw ()  ;



extern unsigned long int __strtoul_internal  (__const char *
						    __nptr,
						  char **   __endptr,
						  int __base, int __group)  throw ()  ;




__extension__
extern long long int __strtoll_internal  (__const char *   __nptr,
					      char **   __endptr,
					      int __base, int __group)  throw ()  ;



__extension__
extern unsigned long long int __strtoull_internal  (__const char *
							  __nptr,
							char **
							  __endptr,
							int __base,
							int __group)  throw ()  ;




# 326 "/usr/include/stdlib.h" 3




 


extern char *l64a  (long int __n)  throw ()  ;

 
extern long int a64l  (__const char *__s)  throw ()  ;


# 1 "/usr/include/sys/types.h" 1 3
 

















 








extern "C" { 



More information about the Gcc-bugs mailing list