On Thu, 27 Aug 2009, Ian Langmore wrote:

> I'd like to pass function pointers as in e.g. c.  In python of course
> function pointers are automatically passed.  I can't find documentation
> on this.  I tried both c and python-like syntax and neither worked.
> Below is my "c-syntax" (failed) attempt.
> ------------------------------------------------------------------------------------------------------------
> cdef float Plus (float a, float b):
>    return a+b
>
> ############
> # This block will not compile
> cdef use_fun_ptr(float a, float b, float (*pt2Func) (float, float)):
>    cdef float result
>    result = pt2Func(a,b)
>    return result
> ############

Works for me, what version of Cython are you using?

> def main():
>    cdef float use_fun_ptr(float, float, float (float, float))

Here you're declaring a new variable, are you sure that's what you want to 
do?

>    # This line works
>    print "Using Plus directly,  " + str(Plus(2,5))
>    #
>    print "Using use_fun_ptr,  " + str( use_fun_ptr(2, 5, &Plus)  )
> ------------------------------------------------------------------------------------------------------------
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to