- Learning Cython Programming(Second Edition)
- Philip Herron
- 191字
- 2021-07-16 09:45:27
Typedef and function pointers
The typedef
in C/C++ code allows the programmer to give a new name or alias to any type. For example, one could typedef
an int
to myint
. Or you can just simply typedef
a struct so that you don't have to refer to the struct with the keyword struct every time. For example, consider this C struct
and typedef
:
struct foobar {
int x;
char * y;
};
typedef struct foobar foobar_t;
In Cython, this can be described by the following:
cdef struct foobar:
int x
char * y
ctypedef foobar foobar_t
Note we can also typedef
pointer types as below:
ctypedef int * int_ptr
We can also typedef
function C/C++ pointers, as follows:
typedef void (*cfptr) (int)
In Cython, this will be as follows:
ctypedef void (*cfptr)(int)
Using the function pointer is just as you would expect:
cdef cfptr myfunctionptr = &myfunc
There is some magic going on here with function pointers as it's simply not safe for raw Python code to directly call a Python function or vice versa. Cython understands this case and will wrap things up for us to make the call safely.
- Python程序設計教程(第2版)
- Mobile Web Performance Optimization
- Getting Started with React
- GeoServer Cookbook
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- 實用防銹油配方與制備200例
- VMware vSphere 6.7虛擬化架構實戰指南
- JavaScript前端開發與實例教程(微課視頻版)
- HTML5 and CSS3 Transition,Transformation,and Animation
- Java編程技術與項目實戰(第2版)
- 零基礎入門學習Python
- The DevOps 2.5 Toolkit
- Android應用案例開發大全(第二版)
- CoffeeScript Application Development Cookbook