c++ header (some.h) contains:
#define NAME_SIZE 42
struct s_X{
char name[NAME_SIZE + 1]
} X;
I want to use X structure in Python. How could I make it?
I write:
cdef extern from "some.h":
cdef int NAME_SIZE # 42
ctypedef struct X:
char name[NAME_SIZE + 1]
And got an error: Not allowed in a constant expression
It often doesn't really matter what you tell Cython when declaring types - it uses the information for checking you aren't doing anything obviously wrong with type casting and that's it. The
cdef extern "some.h"
statement ensures that some.h is included into to c-file Cython creates and ultimately that determines what is complied.Therefore, in this particular case, you can just insert an arbitary number and it will work fine
In situations it won't work though, especially where Cython has to actually use the number in the C code it generates. For example:
(I don't currently have a suggestion as to what to do in this case)