c++ - Non-standard reinterpret_cast behaviour? Section 5.2.10/9
- Don Clugston (9/9) May 30 2004 According to my reading of the standard, section 5.2.10/9 implies that i...
- Walter (8/17) May 31 2004 It will help a lot if you can post a canonical example, please. -Walter
- Don Clugston (30/51) Jun 07 2004 Walter- The following code fails:
-
Walter
(5/34)
Jun 07 2004
Thanks. An example is worth a thousand words
.
According to my reading of the standard, section 5.2.10/9 implies that it should be possible to use reinterpret_cast<> to convert from a member function pointer to any member function pointer (MFP), regardless of type. On every one of the eight other compilers I've tested, such a cast is always successful, provided that both MFPs are the same size (and MFPs must be the same size if the compiler is conformant). DMC doesn't allow this casting unless the classes are related. I find this strange since the MFPs are always the same size. Why is DMC preventing this cast?
May 30 2004
It will help a lot if you can post a canonical example, please. -Walter "Don Clugston" <Don_member pathlink.com> wrote in message news:c9ed6k$2106$1 digitaldaemon.com...According to my reading of the standard, section 5.2.10/9 implies that itshouldbe possible to use reinterpret_cast<> to convert from a member functionpointerto any member function pointer (MFP), regardless of type. On every one of the eight other compilers I've tested, such a cast isalwayssuccessful, provided that both MFPs are the same size (and MFPs must bethe samesize if the compiler is conformant). DMC doesn't allow this casting unless the classes are related. I find this strange since the MFPs are always the same size. Why is DMC preventingthiscast?
May 31 2004
Walter- The following code fails: =============================== class X { public: void func() {}; }; class Y { }; typedef void (X::*XFuncPtr)(void); typedef void (Y::*YFuncPtr)(void); int main(void) { XFuncPtr xp; xp = &X::func; YFuncPtr yp = reinterpret_cast<YFuncPtr>(xp); return 0; } =============================== The code compiles without error on MSVC 4, 6, 7.0, 7.1, Borland BCB 5.5, and on the latest compilers from GCC, Intel x86, Intel Itanium, Comeau, and Metrowerks. In DMC 8.38n, this code produces the following error message: YFuncPtr yp = reinterpret_cast<YFuncPtr>(xp); ^ dmctest.cpp(18) : Error: illegal cast from: void ( X::*member func)() to : void ( Y::*member func)() --- errorlevel 1 ================================ In article <c9eqdi$2m3r$1 digitaldaemon.com>, Walter says...It will help a lot if you can post a canonical example, please. -Walter "Don Clugston" <Don_member pathlink.com> wrote in message news:c9ed6k$2106$1 digitaldaemon.com...According to my reading of the standard, section 5.2.10/9 implies that itshouldbe possible to use reinterpret_cast<> to convert from a member functionpointerto any member function pointer (MFP), regardless of type. On every one of the eight other compilers I've tested, such a cast isalwayssuccessful, provided that both MFPs are the same size (and MFPs must bethe samesize if the compiler is conformant). DMC doesn't allow this casting unless the classes are related. I find this strange since the MFPs are always the same size. Why is DMC preventingthiscast?
Jun 07 2004
Thanks. An example is worth a thousand words <g>. "Don Clugston" <Don_member pathlink.com> wrote in message news:ca38bk$25qf$1 digitaldaemon.com...Walter- The following code fails: =============================== class X { public: void func() {}; }; class Y { }; typedef void (X::*XFuncPtr)(void); typedef void (Y::*YFuncPtr)(void); int main(void) { XFuncPtr xp; xp = &X::func; YFuncPtr yp = reinterpret_cast<YFuncPtr>(xp); return 0; } =============================== The code compiles without error on MSVC 4, 6, 7.0, 7.1, Borland BCB 5.5,and onthe latest compilers from GCC, Intel x86, Intel Itanium, Comeau, andMetrowerks.In DMC 8.38n, this code produces the following error message: YFuncPtr yp = reinterpret_cast<YFuncPtr>(xp); ^ dmctest.cpp(18) : Error: illegal cast from: void ( X::*member func)() to : void ( Y::*member func)() --- errorlevel 1 ================================
Jun 07 2004