Raised This Month: $32 Target: $400
 8% 

Ampersand-Operator Usage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
More
Member
Join Date: Nov 2004
Location: Internet
Old 01-03-2009 , 17:15   Ampersand-Operator Usage
Reply With Quote #1

Hi,

I have a question regarding the ampersand-operator.
I want to store the address of a class-member-function in an void *pointer (not in an class-member-pointer).
(the function is not virtual so no vtable stuff etc to think of)

I wonder why this:
Code:
void *blub2 = (void *)&CVictim::MemFunc;
does NOT compile, but this:
Code:
void *blub  = (void *&)CVictim::MemFunc;
does.

Also i wonder why when I use a dirty union cast:
Code:
union {
  void *pFunc;
  void (CVictim::*mFunc)();
} weldPointers;
weldPointers.mFunc = &CVictim::MemFunc;
void *blub3 = weldPointers.pFunc;
it doesnt give the same result than blub.

Thanks in advance.

More

Edit:

I also wonder why it is possible to use the reference operator 2 times in this case:
Code:
void **blub4  = &(void *&)CVictim::MemFunc;

Last edited by More; 01-03-2009 at 20:32.
More is offline
BAILOPAN
Join Date: Jan 2004
Old 01-04-2009 , 22:42   Re: Ampersand-Operator Usage
Reply With Quote #2

Read this for an in-depth explanation of member function pointers: http://www.codeproject.com/KB/cpp/FastDelegate.aspx

Gist is that when you get a member function pointer you have a complex, compiler-dependent structure -- the language just doesn't guarantee that you can deref it back to an address.

SourceHook can do some decoding for you - probably only virtual calls at the moment though. See SourceHook::GetFuncInfo (and then you can use standard vtable inspection (or SH_GET_ORIG_VFNPTR_ENTRY in MM:S 1.6+ API).

Otherwise, see Don Clugston's excellent article for the structures each compiler uses.
__________________
egg
BAILOPAN is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode