This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Wrapping C++ in C.


> I am not interested in retrieving a member function pointer.  I am
> interested in retrieving a C function pointer out of a member function.
> Please see my original post.

Write a wrapper function, e.g. for

Type1 Foo::bar(Type2* arg);

where Type1 and Type2 are types, write

extern "C" Type1
call_bar_with_Type2_on_Foo(Foo* object, Type2* arg)
{
	return object->bar(arg);
}

and use the function pointer to that.

You may object that you don't want to do this, but want some g++-specific
hack that can call a munged version of the original function directly.  On
some platforms, the original function, at assembler level, has a signature
that looks like the wrapper function above (a pointer to the object is
passed as the first argument and the original arguments follow).  But we
can't promise that this will always be true on all g++ platforms and
versions.  So use the wrapper.

If you don't want the overhead of an extra function call, make Foo::bar
inline.

(This is what the comp.std.c++ folks would tell you, I'm sure).



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]