|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-05-20 10:19:11
Rene Rivera <grafik.list_at_[hidden]> writes:
> In rewriting a plugin interface I use, which for language portability
> uses C function pointers as the entry points, I came up with a
> "make_c_function" utility. I use it to translate C++ functions, any of
> objects, binds, function, members, et. to _real_ C function pointers.
> For example:
>
> class P
> {
> public: int foo(int);
> };
>
> P p;
>
> extern "C"
> {
> void * get_plugin_call(int n)
> {
> if (1 == n)
> {
> return make_c_function<P,int(int)>(
> boost::bind(&p,p::foo,_1));
> }
> else { return 0; }
> }
> }
>
> [example much abbreviated from real life use]
I don't see how this can work.
P p;
Q q;
extern "C" int (*f1)(int)
= make_c_function<P,int(int)>(boost::bind(&p,P::foo,_1));
extern "C" int (*f2)(int)
= make_c_function<P,int(int)>(boost::bind(&q,P::foo,_1));
Don't these call the same function with the same stored data?
ooh, sneaky idea... do you specailize a class template on the address
of the argument to make_c_function, thus generating unique functions?
I would've used that idea in Boost.Python had I thought of it.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk