Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

including enums from a c++ header file into cython

Tags:

enums

cython

What is the difference between these two pieces of cython code?

cdef extern from "some_header.h":

    enum _some_enum:
        ...
    ctypedef _some_enum some_enum

and:

cdef extern enum _some_enum:
    ...
ctypedef _some_enum some_enum

Since you have to redefine the enum in the .pyd file, does it matter if you say anything about the header file? Can I include it from the header file instead of retyping it?

like image 696
dkissick Avatar asked Oct 24 '22 02:10

dkissick


1 Answers

It shouldn't be a problem to let Cython generate enum declarations. However, you typically want to use the header to ensure that the declarations are consistent. Cython will #include the header instead of including its own declarations. That said, it doesn't actually use the declarations in the header to generate code. You still have to write compatible declarations. You can find more information in the user guide: Interfacing with External C Code: Referencing C header files.

like image 128
Eryk Sun Avatar answered Oct 31 '22 10:10

Eryk Sun