From: <no...@so...> - 2002-01-03 09:32:58
|
Bugs item #497495, was opened at 2001-12-28 18:18 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=102435&aid=497495&group_id=2435 Category: gcc Group: None >Status: Closed >Resolution: Invalid Priority: 5 Submitted By: vedad kajtaz (vedad) Assigned to: Danny Smith (dannysmith) Summary: code doesnt compile Initial Comment: Hello, i've got a problem porting a piece of code from linux (gcc version egcs-2.90.27 980315 (egcs-1.0.2 release), yes it is _very_ old) to mingw. The code simply doesnt compile. The problem is about using a class method as a callback. In my project, i'm using a 'void *' as first argument to all callbacks thus being able to 'plug' both c and c++ (by passing class' "this" pointer as first argument) code to my application. This is a sample of code which will raise compiling error: --->8--->8--->8--->8--->8--->8--->8 #include <stdio.h> typedef void (*cback)(void *, unsigned int x); class Test { private: unsigned int me; public: Test(unsigned int me) { this->me = me; } void Callback(int x) { printf("Test::Callback(%d), me=%d\n", x, me); } }; void TestCallback(cback function, void *ptr, unsigned int x) { function(ptr, x); } int main(int argc, char *argv[]) { Test *t1, *t2; t1 = new Test(10); t2 = new Test(20); TestCallback(Test::Callback, t1, 50); TestCallback(Test::Callback, t2, 100); return 0; } --->8--->8--->8--->8--->8--->8--->8 This compiles nicely on linux (except the warning "converting from `void (Test::*)(int)' to `void (*)(void *, unsigned int)") and prints, as expected: Test::Callback(50), me=10 Test::Callback(100), me=20 With g++/mingw, i got a couple of lines that seem to be warnings, but g++ exits with error. thanks -- vedad kajtaz ---------------------------------------------------------------------- >Comment By: Danny Smith (dannysmith) Date: 2002-01-03 01:32 Message: Logged In: YES user_id=11494 It shouldn't compile. The types do not match. void Test::Callback(int) does not not match type void (*)(void*, unsigned int)' and that should throw an error in C++. If there is a bug in mingw version of gcc-2.95 it is in the reporting of the error. In 3.1 this diagnostic is provided: bug.cpp: In function `int main(int, char**)': bug.cpp:36: no matches converting function `Callback' to type `void (*)(void*, unsigned int)' bug.cpp:17: candidates are: void Test::Callback(int) bug.cpp:37: no matches converting function `Callback' to type `void (*)(void*, unsigned int)' bug.cpp:17: candidates are: void Test::Callback(int) Danny ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=102435&aid=497495&group_id=2435 |