complex cython type and its representation in C/C++

84 views
Skip to first unread message

Michael Wimmer

unread,
May 27, 2011, 5:50:20 PM5/27/11
to cython-users
Dear all,

I have a question regarding a statement from the documentation in
"Interfacing with External C Code". When explaining the cdef extern
from "include.h": statement, it is written:

"When you use an extern definition on its own as in the examples
above, Cython includes a declaration for it in the generated C file.
This can cause problems if the declaration doesn’t exactly match the
declaration that will be seen by other C code. If you’re wrapping an
existing C library, for example, it’s important that the generated C
code is compiled with exactly the same declarations as the rest of the
library."

Could you maybe elaborate on that statement with an example? For C++
code, I would agree (there the exact function definition matters
because of namemangling). For pure C code I can't really see an
example (except the trivial case where the cython definition is simply
wrong).

Thanks,
Michael


Robert Bradshaw

unread,
May 27, 2011, 6:11:01 PM5/27/11
to cython...@googlegroups.com

It is referring to bare extern declarations, "When you use an extern
definition on its own **as in the examples above**." In this case, bad
things can happen if you declare a function with the wrong signature
or declare an int where a long was expected, and then link against a
library with (incompatible) definitions for the same names. Really,
this is just the same caviate as using "extern" in C or C++. If header
files are available, you should almost always be using the "cdef
extern from" form.

As for complex numbers, Cython provides its own implementation for
them in C (as the C standard doesn't require them), but if complex.h
is included (directly or indirectly) it uses the "native" c99 types.
For C++ it always uses the C++ complex types.

- Robert

Reply all
Reply to author
Forward
0 new messages