Wrapping C++ in C.

Joe Buck jbuck@synopsys.COM
Fri Feb 4 09:11:00 GMT 2000


> 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).




More information about the Gcc mailing list