From: <dan...@ya...> - 2002-11-18 20:01:43
|
--- Ranjit Mathew <rm...@ho...> wrote: > Hi, > > I'm facing a thorny problem with assignment of > __stdcall functions to function pointers - the weird > part is that MinGW GCC 3.2, BCC 5.5 and MSVC 6 all give > *different* errors for the same program! Can any of > you provide insights into this behaviour? > > 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< ------------------------- > The following is not quite right, but close ( I don't pretend to understand the C++ parser that well): In C++ parsing, (3) and (5) mean different things. In (3) the stdcall attribute applies to the the function. In (5) it applies to the type return by the function (which doesn't make sense). Hence with 5 the conversion is invalid. There was (is) a related (PR c++/6626) in GNATS database on this. See (eg): http://gcc.gnu.org/ml/gcc-bugs/2002-10/msg00809.html In GCC (C lang), both forms have the same meaning. That is the bug IMHO. Danny http://careers.yahoo.com.au - Yahoo! Careers - 1,000's of jobs waiting online for you! |