Search code examples
pythonsyntaxheadercython

Cython: Are there differences between `cdef public: void f()` and `cdef public: cdef void f()`


A function in .pxd file and be define this way:

cdef public:
    void f()

Or this way:

cdef public:
    cdef void f()

Both cases are compiled fine without errors. I wonder about the differences between those two and which one is the real C function?


Solution

  • Tested it out myself, the result is: They're exactly the same.

    I've checked out *.h, *_api.h, *.c, *.cpp output files of Cython transpiler for a test module with the definitions stated in the question and they equal in every byte.

    Conclusion: The 2nd cdef is redundant.