On 01/02/13 09:31, Sturla Molden wrote:
cdef object a
cdef list b
cdef foobar c
etc to define Python variables. 'cdef' seems to indicate that it is a C
declaration, yet here it is not.
Yes, it is. In this context, the cdef isn't about the type of the
variable, it's about where and how it's stored and accessed. The
above declarations result in the generation of C code something like:
PyObject *a;
PyListObject *b;
Foobar *c;
They are then accessed directly by the generated C code.
Without the cdef, these variables would be stored wherever Python
normally stores variables for the relevant scope, which could be
in a module or instance dict, and the usual Python/C API machinery
is used to access them.
Distinguishing between Python and C types would be problematic
anyway, since a PyObject* is both a Python type *and* a C type.
Neither does this cdef syntax allow us to declare Python int and float
statically.
I've never found the need to declare a Python int or float
statically, but a way could be provided to access these types
if need be. Maybe Cython has already done this, I don't know.
--
Greg
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel