Cython中有任何功能类型吗?

Cython中有任何功能类型吗?,第1张

Cython中有任何功能类型吗?

应该不言自明..?:)

# Define a new type for a function-type that accepts an integer and# a string, returning an integer.ctypedef int (*f_type)(int, str)# Extern a function of that type from foo.hcdef extern from "foo.h":    int do_this(int, str)# Passing this function will not work.cpdef int do_that(int a, str b):    return 0# However, this will work.cdef int do_stuff(int a, str b):    return 0# This functio uses a function of that type. Note that it cannot be a# cpdef function because the function-type is not available from Python.cdef void foo(f_type f):    print f(0, "bar")# Works:foo(do_this)   # the externed functionfoo(do_stuff)  # the cdef function# Error:# Cannot assign type 'int (int, str, int __pyx_skip_dispatch)' to 'f_type'foo(do_that)   # the cpdef function


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5662775.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存