<div dir="ltr">Member function pointers are two pointers wide on Itanium. They look like this:<div style>struct {<br> union {</div><div style> void *NonVirtualFunctionPointer;</div><div style> ptrdiff_t VTableIndex;</div>
<div style> };</div><div style> ptrdiff_t ThisAdjustment;</div><div style>};</div><div style><br></div><div style>It's not surprising the reinterpret_cast fails. It seems gcc will try to give you the function pointer part, and hope that you ultimately apply it to an object that doesn't require an adjustment.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, May 19, 2013 at 5:31 AM, salvatore benedetto <span dir="ltr"><<a href="mailto:salvatore.benedetto@gmail.com" target="_blank">salvatore.benedetto@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've sent this to cfe-users but perhaps it was better to send<br>
it here.<br>
<br>
S.<br>
<br>
<br>
---------- Forwarded message ----------<br>
From: salvatore benedetto <<a href="mailto:salvatore.benedetto@gmail.com">salvatore.benedetto@gmail.com</a>><br>
Date: Sun, May 19, 2013 at 10:57 AM<br>
Subject: Can't get address of member-function<br>
To: <a href="mailto:cfe-users@cs.uiuc.edu">cfe-users@cs.uiuc.edu</a><br>
<br>
<br>
Hi there,<br>
<br>
first of all, I know the following should not be done usually, but I'm working<br>
with C++ on a bare-metal project and it seems not to be forbidden by<br>
the standard.<br>
<br>
I need to get the address of a non-static member function and assign<br>
it to an integer variable.<br>
<br>
class MyClass<br>
{<br>
public:<br>
MyClass()<br>
{<br>
//someAddress = (uint32_t)&run; // This works OK with static<br>
member function<br>
someAddress = (uint32_t)reinterpret_cast<void (*)()>(&MyClass::run);<br>
}<br>
<br>
private:<br>
<br>
//static void run()<br>
void run()<br>
{<br>
;<br>
}<br>
<br>
public:<br>
uint32_t someAddress;<br>
};<br>
<br>
This code compiles with a warning with GCC, but I get the following<br>
error with clang 3.2<br>
<br>
address_of_member_function.cpp:10:33: error: reinterpret_cast from<br>
'void (MyClass::*)()' to 'void (*)()' is not allowed<br>
someAddress = (uint32_t)reinterpret_cast<void (*)()>(&MyClass::run);<br>
<br>
Is this a bug in clang or am I missing something?<br>
<br>
Regards,<br>
Salvatore<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>