public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* calling a C++ member function
@ 2012-06-13 10:56 Xin Tong
  2012-06-13 12:51 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Xin Tong @ 2012-06-13 10:56 UTC (permalink / raw)
  To: gcc-help

Function pointers can be used to call functions in C. but for C++
member functions. A special function pointer needs to be used, i.e.

float (SomeClass::*my_memfunc_ptr)(int, char *);

but eventually, my_memfunc_ptr will hold the address of the code of
the function it points to. can i set up the calling context myself at
this point, i.e. put "this" pointer into rdi, put the arguments into
other registers/stacks and jump to the address held in the
my_memfunc_ptr. would this work in gcc compiled code , what about
other compilers and os linkages ?

Thanks

Xin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: calling a C++ member function
  2012-06-13 10:56 calling a C++ member function Xin Tong
@ 2012-06-13 12:51 ` Jonathan Wakely
  2012-06-13 14:05   ` Xin Tong
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2012-06-13 12:51 UTC (permalink / raw)
  To: Xin Tong; +Cc: gcc-help

On Jun 13, 2012 11:56 AM, "Xin Tong" wrote:
>
> Function pointers can be used to call functions in C. but for C++
> member functions. A special function pointer needs to be used, i.e.
>
> float (SomeClass::*my_memfunc_ptr)(int, char *);
>
> but eventually, my_memfunc_ptr will hold the address of the code of
> the function it points to. can i set up the calling context myself at
> this point, i.e. put "this" pointer into rdi, put the arguments into
> other registers/stacks and jump to the address held in the
> my_memfunc_ptr. would this work in gcc compiled code , what about
> other compilers and os linkages ?

Have you seen http://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: calling a C++ member function
  2012-06-13 12:51 ` Jonathan Wakely
@ 2012-06-13 14:05   ` Xin Tong
  0 siblings, 0 replies; 3+ messages in thread
From: Xin Tong @ 2012-06-13 14:05 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

On Wed, Jun 13, 2012 at 8:51 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On Jun 13, 2012 11:56 AM, "Xin Tong" wrote:
>>
>> Function pointers can be used to call functions in C. but for C++
>> member functions. A special function pointer needs to be used, i.e.
>>
>> float (SomeClass::*my_memfunc_ptr)(int, char *);
>>
>> but eventually, my_memfunc_ptr will hold the address of the code of
>> the function it points to. can i set up the calling context myself at
>> this point, i.e. put "this" pointer into rdi, put the arguments into
>> other registers/stacks and jump to the address held in the
>> my_memfunc_ptr. would this work in gcc compiled code , what about
>> other compilers and os linkages ?
>
> Have you seen http://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html ?

Ok. did not know that before. it seems member functions are callable
with instruction address. especially with PMF enabled. one can take
the address without an object.

Thanks

Xin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-13 14:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-13 10:56 calling a C++ member function Xin Tong
2012-06-13 12:51 ` Jonathan Wakely
2012-06-13 14:05   ` Xin Tong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).