Commit 570ff121 authored by Stefan Behnel's avatar Stefan Behnel

rewrite 'types' sections in language basics and pure mode docs

parent 2fcf3a39
...@@ -179,6 +179,27 @@ Static typing ...@@ -179,6 +179,27 @@ Static typing
explicit_c_type: {'ctype': 'int'}): explicit_c_type: {'ctype': 'int'}):
... ...
C types
^^^^^^^
There are numerous types built into the Cython module. It provides all the
standard C types, namely ``char``, ``short``, ``int``, ``long``, ``longlong``
as well as their unsigned versions ``uchar``, ``ushort``, ``uint``, ``ulong``,
``ulonglong``. The special ``bint`` type is used for C boolean values and
``Py_ssize_t`` for (signed) sizes of Python containers.
For each type, there are pointer types ``p_int``, ``pp_int``, . . ., up to
three levels deep in interpreted mode, and infinitely deep in compiled mode.
Further pointer types can be constructed with ``cython.pointer(cython.int)``,
and arrays as ``cython.int[10]``. A limited attempt is made to emulate these
more complex types, but only so much can be done from the Python language.
The Python types int, long and bool are interpreted as C ``int``, ``long``
and ``bint`` respectively. Also, the Python builtin types ``list``, ``dict``,
``tuple``, etc. may be used, as well as any user defined types.
Extension types and cdef functions Extension types and cdef functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -68,24 +68,24 @@ an anonymous :keyword:`enum` declaration for this purpose, for example,:: ...@@ -68,24 +68,24 @@ an anonymous :keyword:`enum` declaration for this purpose, for example,::
Types Types
----- -----
There are numerous types built in to the Cython module. It provides all the Cython uses the normal C syntax for C types, including pointers. It provides
standard C types, namely ``char``, ``short``, ``int``, ``long``, ``longlong`` all the standard C types, namely ``char``, ``short``, ``int``, ``long``,
as well as their unsigned versions ``uchar``, ``ushort``, ``uint``, ``ulong``, ``long long`` as well as their ``unsigned`` versions, e.g. ``unsigned int``.
``ulonglong``. One also has ``bint`` and ``Py_ssize_t``. The special ``bint`` type is used for C boolean values (``int`` with 0/non-0
values for False/True) and ``Py_ssize_t`` for (signed) sizes of Python
For each type, there are pointer types ``p_int``, ``pp_int``, . . ., up to containers.
three levels deep in interpreted mode, and infinitely deep in compiled mode.
Pointer types are constructed as in C, by appending a ``*`` to the base type
The Python types int, long and bool are interpreted as C ``int``, ``long`` they point to, e.g. ``int**`` for a pointer to a pointer to a C int.
and ``bint`` respectively. Arrays use the normal C array syntax, e.g. ``int[10]``. Note that Cython uses
array access for pointer dereferencing, as ``*x`` is not valid Python syntax,
Also, the Python types ``list``, ``dict``, ``tuple``, . . . may whereas ``x[0]`` is.
be used, as well as any user defined types. However at the moment they add very
few in terms of optimization to a simple ``object`` typing. Also, the Python types ``list``, ``dict``, ``tuple``, etc. may be used for
static typing, as well as any user defined extension types. The Python types
Pointer types may be constructed with ``cython.pointer(cython.int)``, and int and long are not available for static typing and instead interpreted as C
arrays as ``cython.int[10]``. A limited attempt is made to emulate these more ``int`` and ``long`` respectively, as statically typing variables with Python
complex types, but only so much can be done from the Python language. integer types has zero advantages.
Grouping multiple C declarations Grouping multiple C declarations
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment