Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
33f19029
Commit
33f19029
authored
May 14, 2018
by
scoder
Committed by
GitHub
May 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2255 from gabrieldemarmiesse/reworked_types
Improved "Types" section.
parents
bb54f5e0
fab0d8b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+19
-3
No files found.
docs/src/userguide/language_basics.rst
View file @
33f19029
...
@@ -153,10 +153,20 @@ Note that Cython uses array access for pointer dereferencing, as ``*x`` is not v
...
@@ -153,10 +153,20 @@ Note that Cython uses array access for pointer dereferencing, as ``*x`` is not v
whereas ``x[0]`` is.
whereas ``x[0]`` is.
Also, the Python types ``list``, ``dict``, ``tuple``, etc. may be used for
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
static typing, as well as any user defined :ref:`extension-types`.
int, long, and float are not available for static typing and instead interpreted as C
For example::
``int``, ``long``, and ``float`` respectively, as statically typing variables with these Python
cdef list foo = []
This requires an *exact* match of the class, it does not allow
subclasses. This allows Cython to optimize code by accessing
internals of the builtin class.
For this kind of typing, Cython uses internally a C variable of type ``PyObject*``.
The Python types int, long, and float are not available for static
typing and instead interpreted as C ``int``, ``long``, and ``float``
respectively, as statically typing variables with these Python
types has zero advantages.
types has zero advantages.
While these C types can be vastly faster, they have C semantics.
While these C types can be vastly faster, they have C semantics.
Specifically, the integer types overflow
Specifically, the integer types overflow
and the C ``float`` type only has 32 bits of precision
and the C ``float`` type only has 32 bits of precision
...
@@ -165,6 +175,12 @@ and is typically what one wants).
...
@@ -165,6 +175,12 @@ and is typically what one wants).
If you want to use these numeric Python types simply omit the
If you want to use these numeric Python types simply omit the
type declaration and let them be objects.
type declaration and let them be objects.
It is also possible to declare :ref:`extension-types` (declared with ``cdef class``).
This does allow subclasses. This typing is mostly used to access
``cdef`` methods and attributes of the extension type.
The C code uses a variable which is a pointer to a structure of the
specific type, something like ``struct MyExtensionTypeObject*``.
Grouping multiple C declarations
Grouping multiple C declarations
--------------------------------
--------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment