mingw32 (gcc 2.95 on Windows) - member function pointer problem
Mumit Khan
khan@nanotech.wisc.EDU
Thu Sep 30 19:57:00 GMT 1999
LauraM3017@aol.com writes:
>
> --part1_bf7a2542.251d712a_boundary
> Content-Type: text/plain; charset="us-ascii"
> Content-Transfer-Encoding: 7bit
>
> Am currently running gcc 2.95 (mingw32) on a Windows NT machine.
>
> I need an array of member function pointers for use in calling a
> particular member function within its class. The technique I'm using
> is based on the information I got from the C++ FAQ. The program worked
> fine with the previous version of mingw32. Am sending a very simplified
> version of the code that still shows the bug.
>
> Below is the command line and output. Attached is the zipped .ii file.
>
> Thanks.
>
> Laura Michaels
>
>
> > cd .
> > g++ -c egcstest.cpp
>
>
> A:\>g++ -c egcstest.cpp
> egcstest.cpp: In method `void eval::function_map(int)':
> egcstest.cpp:42: taking the address of a non-static member function
> egcstest.cpp:42: to form a pointer to member function, say `&eval::do_func1
> '
> egcstest.cpp:42: taking the address of a non-static member function
> egcstest.cpp:42: to form a pointer to member function, say `&eval::do_func2
> '
> egcstest.cpp:42: taking the address of a non-static member function
> egcstest.cpp:42: to form a pointer to member function, say `&eval::do_func3
> '
> egcstest.cpp:43: taking the address of a non-static member function
> egcstest.cpp:43: to form a pointer to member function, say `&eval::do_func4
> '
> egcstest.cpp:43: taking the address of a non-static member function
> egcstest.cpp:43: to form a pointer to member function, say `&eval::do_func5
> '
> egcstest.cpp:43: Internal compiler error in `const_hash', at varasm.c:2372
> Please submit a full bug report.
> See <URL: http://egcs.cygnus.com/faq.html#bugreport > for instructions.
Laura,
You do need to specify the correct syntax for pointer to member function.
However, even after that, gcc-2.95.x has a bug that will crash the compiler
(it's fixed in dev branch) during the automatic array initialization.
You'll see that the array init crashes the compiler if the number of
initializers exceed *two*.
The workaround is to (1) use a static array, or (2) individually assign
the elements.
void function_map (int funcloc)
{
typedef void (eval::* FUNC) (string);
FUNC commfuncs[5];
commfuncs[0] = &eval::do_func1;
commfuncs[1] = &eval::do_func2;
commfuncs[2] = &eval::do_func3;
commfuncs[3] = &eval::do_func4;
commfuncs[4] = &eval::do_func5;
string str = "test";
((this)->*(commfuncs[funcloc])) (str);
}
Regards,
Mumit
More information about the Gcc-bugs
mailing list