From: Benjamin R. <Ben...@ep...> - 2002-11-18 17:45:49
|
Hi Ranjit, Ranjit Mathew <rm...@ho...> writes: > The program in question (with line numbers for ref.) is: > ---------------------- 8< ------------------------- > 1 extern int * (__stdcall *fooPtr)( void); > 2 > 3 int * __stdcall barFn01( void) { return 0; } > 4 > 5 __stdcall int * barFn02( void) { return 0; } > 6 > 7 void snafu( void) > 8 { > 9 fooPtr = barFn01; > 10 fooPtr = barFn02; > 11 } > ---------------------- 8< ------------------------- > > Here's what MinGW GCC 3.2 says: > ---------------------- 8< ------------------------- > /tmp/tt/ptr > gcc -c t.cpp > t.cpp: In function `void snafu()': > t.cpp:9: invalid conversion from `int*(*)()' to `int*(*)()' > ---------------------- 8< ------------------------- Doesn't give any problems for me. When I add calls to the function pointer and output to the functions, it even works ;-). Are you sure, you are running the latest? My version says: >>>>>>>>> C:\tmp> gcc --version gcc (GCC) 3.2 (mingw special 20020817-1) Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. C:\tmp> <<<<<<<<< > Here's what the free BCC 5.5 says: > ---------------------- 8< ------------------------- > C:\TEMP\tt\ptr>bcc32 /c t.cpp > Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland > t.cpp: > Error E2040 t.cpp 5: Declaration terminated incorrectly > *** 1 errors in Compile *** > ---------------------- 8< ------------------------- So "barFn02" (line 5) is invalid according to BCC. > And finally, here's what MSVC 6 says: > ---------------------- 8< ------------------------- > f:\ranjit\cpp\t.cpp(5) : warning C4518: 'int ' : storage-class or type > specifier(s) unexpected here; ignored > f:\ranjit\cpp\t.cpp(5) : warning C4230: anachronism used : > modifiers/qualifiers interspersed, qualifier ignored > f:\ranjit\cpp\t.cpp(5) : error C2165: 'left-side modifier' : cannot modify > pointers to data > > f:\ranjit\cpp\t.cpp(5) : error C2501: 'barFn02' : missing > storage-class or type specifiers Again "barFn02" (line 5) is considered invalid. > f:\ranjit\cpp\t.cpp(10) : error C2440: '=' : cannot convert from 'int > *(__cdecl *)(void)' to 'int *(__stdcall *)(void)' > This conversion requires a reinterpret_cast, a C-style cast or > function-style cast Which is probably just a consequence of the other error. Conclusion: You should drop the form in line 5, because it is obviously not supported by the commercial compilers. so long, benny |