[C++-sig] (Nat Goodspeed) pass function pointerto c
Qinfeng(Javen) Shi
shiqinfeng at gmail.com
Mon Oct 9 02:18:35 CEST 2006
Hi Nat,
Thank you very much.
I tried what you said, but it seems boost::python::object can't be converted
to float by (float) (op(a,b)). So I converted the pointer of op's result
into float*, but got a unexpected result. Something wrong with my code?
-------------------------c extension---------------
boost::python::object op;
void process(arg1,..., boost::python::object arg_op){
...
op = arg_op;
...
float a = 1;
float b = 2;
boost::python::object rlt = op(a,b);
float * f = (float *) (rlt.ptr());
printf("%f \n",*f);
...
}
---------------------result-----------------------------
>>> import hello
>>> hello.funcPtrTest(hello.add)
0.000000
>>> hello.funcPtrTest(hello.minus)
0.000000
>>>
--
Qinfeng(Javen) Shi
Research School of Information Sciences and Engineering
Australian National University
Locked Bag 8001
Canberra ACT 2601
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20061009/42fa30ac/attachment.htm>
More information about the Cplusplus-sig
mailing list