Thread overview
Non-standard reinterpret_cast behaviour? Section 5.2.10/9
May 31, 2004
Don Clugston
May 31, 2004
Walter
Jun 08, 2004
Don Clugston
Jun 08, 2004
Walter
May 31, 2004
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 31, 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 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?
>
>


June 08, 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 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?
>>
>>
>
>


June 08, 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 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
>
> ================================