www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Non-standard reinterpret_cast behaviour? Section 5.2.10/9

↑ ↓ ← Don Clugston <Don_member pathlink.com> writes:
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
↑ ↓ "Walter" <newshound digitalmars.com> writes:
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 it

 be possible to use reinterpret_cast<> to convert from a member function

 to any member function pointer (MFP), regardless of type.

 On every one of the eight other compilers I've tested, such a cast is

 successful, provided that both MFPs are the same size (and MFPs must be

 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

 cast?

May 31 2004
↑ ↓ Don Clugston <Don_member pathlink.com> writes:
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 it

 be possible to use reinterpret_cast<> to convert from a member function

 to any member function pointer (MFP), regardless of type.

 On every one of the eight other compilers I've tested, such a cast is

 successful, provided that both MFPs are the same size (and MFPs must be

 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

 cast?


Jun 07 2004
↑ ↓ → "Walter" <newshound digitalmars.com> writes:
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,

 the latest compilers from GCC, Intel x86, Intel Itanium, Comeau, and

 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