Arrays Cython中的指针数组

Arrays Cython中的指针数组,arrays,cython,Arrays,Cython,我有以下Cythoncode(语法基于帖子): 来自libc.stdlib cimport malloc,免费 def test_func(): cdef int n=10 cdef char*array=malloc(n*sizeof(char*)) 对于范围(n)中的i: 数组[i]=NULL 自由(数组) 它抛出编译时错误: Error compiling Cython file: -----------------------------------------------------

我有以下
Cython
code(语法基于帖子):

来自libc.stdlib cimport malloc,免费
def test_func():
cdef int n=10
cdef char*array=malloc(n*sizeof(char*))
对于范围(n)中的i:
数组[i]=NULL
自由(数组)
它抛出编译时错误:

Error compiling Cython file:
------------------------------------------------------------
...

def test_func():
    cdef int n = 10
    cdef char *array = <char *>malloc(n * sizeof(char*))
    for i in range(n):
        array[i] = NULL
                  ^
------------------------------------------------------------

test.pyx:7:19: Cannot assign type 'void *' to 'char'
编译Cython文件时出错: ------------------------------------------------------------ ... def test_func(): cdef int n=10 cdef char*array=malloc(n*sizeof(char*)) 对于范围(n)中的i: 数组[i]=NULL ^ ------------------------------------------------------------ test.pyx:7:19:无法将类型“void*”分配给“char”
出于某种原因,正在生成一个
char
数组,而不是
char*
。因此,有谁能帮我在
Cython
中获得
char*
数组吗?

我已经找到了它。正确的语法是:

cdef char **array = <char**>malloc(n * sizeof(char*))
cdef char**array=malloc(n*sizeof(char*))
cdef char **array = <char**>malloc(n * sizeof(char*))