dave@HANAUMA.STANFORD.EDU (Dave Nichols) (12/07/89)
A problem with pointers to member functions ?
g++ 1.36.2- + patches posted in gnu.g++.bug ( also fails with 1.36.0 )
Running on a convex-c1 (convex unix 7.1), collect2 is used for loading.
tm.h@ -> ./config/tm-convex1.h
md@ -> ./config/convex.md
This code is derived from the squares demo in Interviews, there appears to
be problem with pointers to member functions when vtbls are used.
If the code is compiled with -Dvtbl ( which forces the class to have a
virtual function table ) it fails, see below.
This code works fine ether way on a sun4 and a DECstation3100.
Script started on Wed Dec 6 14:18:33 1989
hanauma 301> cat testdn.c
#include <stream.h>
class SquaresFrame;
typedef void (SquaresFrame::*MenuFunc)();
class SquaresFrame {
public:
SquaresFrame();
void DoCommands( MenuFunc[], int );
void Print1();
#ifdef vtbl
virtual void Print2();
#else
void Print2();
#endif
};
SquaresFrame::SquaresFrame () { }
void SquaresFrame::DoCommands( MenuFunc funcs[], int num ) {
for (int i = 0; i <num ; i++) {
( this->*funcs[i])();
}
}
void SquaresFrame::Print1() { cout << "1 \n" ; }
void SquaresFrame::Print2() { cout << "2 \n" ; }
main() {
MenuFunc funclist[2] = { &SquaresFrame::Print1 , &SquaresFrame::Print2 };
SquaresFrame* test= new SquaresFrame();
test->DoCommands(funclist,2);
}
****** The SquaresFrame class doesn't have a vtbl in this case ********
hanauma 302> g++ -v -g -I/usr/local/include/g++-include testdn.c
g++ version 1.36.2- (based on GCC 1.36)
/usr/local/lib/gcc-cpp -+ -v -I/usr/local/include/g++-include -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dconvex -Dparsec -Dunix -D__convex__ -D__parsec__ -D__unix__ testdn.c /usr/tmp/cc023439.cpp
GNU CPP version 1.36
/usr/local/lib/gcc-cc1plus /usr/tmp/cc023439.cpp -quiet -dumpbase testdn.c -g -version -o /usr/tmp/cc023439.s
GNU C++ version 1.36.2- (based on GCC 1.36) (convex) compiled by GNU C version 1.36.
default target switches: -mc1
as -o testdn.o /usr/tmp/cc023439.s
/usr/local/lib/gcc-ld /lib/crt0.o testdn.o -lg++ /usr/local/lib/gcc-gnulib -lg -lc
hanauma 303> a.out
1
2
****** now force the SquaresFrame class to have a vtbl ********
hanauma 304> g++ -v -g -I/usr/local/include/g++-include testdn.c -Dvtbl
g++ version 1.36.2- (based on GCC 1.36)
/usr/local/lib/gcc-cpp -+ -v -Dvtbl -I/usr/local/include/g++-include -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dconvex -Dparsec -Dunix -D__convex__ -D__parsec__ -D__unix__ testdn.c /usr/tmp/cc023488.cpp
GNU CPP version 1.36
/usr/local/lib/gcc-cc1plus /usr/tmp/cc023488.cpp -quiet -dumpbase testdn.c -g -version -o /usr/tmp/cc023488.s
GNU C++ version 1.36.2- (based on GCC 1.36) (convex) compiled by GNU C version 1.36.
default target switches: -mc1
as -o testdn.o /usr/tmp/cc023488.s
/usr/local/lib/gcc-ld /lib/crt0.o testdn.o -lg++ /usr/local/lib/gcc-gnulib -lg -lc
hanauma 305> a.out
Segmentation fault (core dumped)
hanauma 306> gdb a.out
GDB 3.4, Copyright (C) 1989 Free Software Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /sep/dave/test/g++/a.out...done.
Type "help" for a list of commands.
(gdb) run
Starting program: /sep/dave/test/g++/a.out
Program received signal 11, Segmentation fault
0x80000000 in gen$soff ()
(gdb) where
#0 0x80000000 in gen$soff ()
#1 0x80001260 in DoCommands__12SquaresFramePPM12SquaresFrameFv_vi (...) (...)
#2 0x800013f2 in main (...) (...)
(gdb) up
Reading in symbols for testdn.c...done.
#1 0x80001260 in DoCommands__12SquaresFramePPM12SquaresFrameFv_vi ($this=(SquaresFrame *) 0x80019000, funcs=(MenuFunc *) 0xffffcda8, num=2) (testdn.c line 26)
26 ( this->*funcs[i])();
(gdb) p funcs[0]
$1 = (MenuFunc) (MenuFunc) 268436047
(gdb) q
The program is running. Quit anyway? (y or n) y
Notes
-----
(1) gdb on the convex never seems to print out the member functions nicely
like it does on a sun4, this may or may not be related.
(2) If only one function is present (remove all references to print1 ) it
works fine.