I have the following Cython code (the syntax is based on the post https://stackoverflow.com/a/13983740/4189299):
from libc.stdlib cimport malloc, free
def test_func():
cdef int n = 10
cdef char *array = <char *>malloc(n * sizeof(char*))
for i in range(n):
array[i] = NULL
free(array)
It throws the compile-time error:
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'
For some reason an array of char instead of char* is getting generated. Therefore, can anyone help me to obtain an array of char* in Cython?