函數指針作爲參數賦值
案例
#include<stdio.h> void show() { printf("%s\n",__FUNCTION__); } void cool(void(**s)()){ *s = &show; } ~
賦值的是
show
文件名編譯
gcc -fPIC --shared test.c -o test.so
python
代碼
import ctypes VOID_T = ctypes.CFUNCTYPE(None) t = VOID_T() handle=ctypes.CDLL("./test.so") handle.cool.argtypes=[ctypes.POINTER(VOID_T)] handle.cool(ctypes.pointer(t)) t()
執行
輸出函數名
show
.