vendredi 29 mai 2015

How to create empty char arrays in Cython without loops

Well, this seems easy, but I can't find a single reference on the web. In C we can create a char array of n null-characters as follows:

char arr[n] = "";

But when I try to do the same in Cython with

cdef char arr[n] = ""

I get this compilation error:

Error compiling Cython file:
------------------------------------------------------------
...
cdef char a[n] = ""
                   ^
------------------------------------------------------------

Syntax error in C variable declaration

Obviously Cython doesn't allow to declare arrays this way, but is there an alternative? I don't want to manually set each item in the array, i.e. I'm not looking for something like this

cdef char a[10]
for i in range(0, 10, 1):
    a[i] = b"\0"

Aucun commentaire:

Enregistrer un commentaire