This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Wrapping C++ in C.
- To: kevinatk at home dot com (Kevin Atkinson)
- Subject: Re: Wrapping C++ in C.
- From: Joe Buck <jbuck at synopsys dot COM>
- Date: Fri, 4 Feb 2000 09:09:52 -0800 (PST)
- Cc: pedwards at jaj dot com (Phil Edwards), gcc at gcc dot gnu dot org
> 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).