On Sun, May 19, 2013 at 1:21 PM, salvatore benedetto <span dir="ltr"><<a href="mailto:salvatore.benedetto@gmail.com" target="_blank">salvatore.benedetto@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Sun, May 19, 2013 at 2:12 PM, Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br>
> Member function pointers are two pointers wide on Itanium.  They look like<br>
> this:<br>
> struct {<br>
>   union {<br>
>     void *NonVirtualFunctionPointer;<br>
>     ptrdiff_t VTableIndex;<br>
>   };<br>
>   ptrdiff_t ThisAdjustment;<br>
> };<br>
><br>
> It's not surprising the reinterpret_cast fails.  It seems gcc will try to<br>
> give you the function pointer part, and hope that you ultimately apply it to<br>
> an object that doesn't require an adjustment.<br>
><br>
<br>
</div>Under the assumption that I know what I am doing with that pointer, that is<br>
no virtual members and no multiple inheritance, would it be wrong to have<br>
clang return the NonVirtualFunctionPointer like GCC, along with a warning<br>
at most?<div class="HOEnZb"><div class="h5"></div></div></blockquote><div><br></div><div>It would be a language extension, so you would need to justify the cost of including it in Clang. I believe the GCC extension you want is the one documented here:</div>
<div><br></div><div><a href="http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Bound-member-functions.html#Bound-member-functions">http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Bound-member-functions.html#Bound-member-functions</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
> On Sun, May 19, 2013 at 5:31 AM, salvatore benedetto<br>
> <<a href="mailto:salvatore.benedetto@gmail.com">salvatore.benedetto@gmail.com</a>> wrote:<br>
>><br>
>> 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<br>
>> 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<br>
>> (*)()>(&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<br>
>> (*)()>(&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>
><br>
><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>
</div></div></blockquote></div><br>