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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
bb54f5e0
Commit
bb54f5e0
authored
May 14, 2018
by
scoder
Committed by
GitHub
May 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2254 from gabrieldemarmiesse/transfering_cdef_statement
Transfered cdef statement.
parents
b61a6147
0670cb70
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+45
-0
No files found.
docs/src/userguide/language_basics.rst
View file @
bb54f5e0
...
...
@@ -68,6 +68,20 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
See also :ref:`struct-union-enum-styles`
.. note::
Structs can be declared as ``cdef packed struct``, which has
the same effect as the C directive ``#pragma pack(1)``.
Declaring an enum as ``cpdef`` will create a :pep:`435`-style Python wrapper::
cpdef enum CheeseState:
hard = 1
soft = 2
runny = 3
There is currently no special syntax for defining a constant, but you can use
an anonymous :keyword:`enum` declaration for this purpose, for example,::
...
...
@@ -92,6 +106,35 @@ an anonymous :keyword:`enum` declaration for this purpose, for example,::
ctypedef int* IntPtr
It is also possible to declare functions with :keyword:`cdef`, making them c functions.
::
cdef int eggs(unsigned long l, float f):
...
You can read more about them in :ref:`python_functions_vs_c_functions`.
You can declare classes with :keyword:`cdef`, making them :ref:`extension-types`. Those will
have a behavior very close to python classes, but are faster because they use a ``struct``
internally to store attributes.
Here is a simple example::
cdef class Shrubbery:
cdef int width, height
def __init__(self, w, h):
self.width = w
self.height = h
def describe(self):
print "This shrubbery is", self.width, \
"by", self.height, "cubits."
You can read more about them in :ref:`extension-types`.
Types
-----
...
...
@@ -141,6 +184,8 @@ can group them into a :keyword:`cdef` block like this::
print s.tons, "Tons of spam"
.. _python_functions_vs_c_functions:
Python functions vs. C functions
==================================
...
...
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