Skip to content

Commit

Permalink
Put a code snippet from external_c_code.rst into the examples directo…
Browse files Browse the repository at this point in the history
…ry for testing.
  • Loading branch information
gabrieldemarmiesse committed Jun 17, 2018
1 parent 5c04c1a commit 63b3b84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 9 additions & 0 deletions docs/examples/userguide/external_C_code/c_code_docstring.pyx
@@ -0,0 +1,9 @@
cdef extern from *:
"""
/* This is C code which will be put
* in the .c file output by Cython */
static long square(long x) {return x * x;}
#define assign(x, y) ((x) = (y))
"""
long square(long x)
void assign(long& x, long y)
12 changes: 2 additions & 10 deletions docs/src/userguide/external_C_code.rst
Expand Up @@ -332,17 +332,9 @@ Including verbatim C code
-------------------------

For advanced use cases, Cython allows you to directly write C code
as "docstring" of a ``cdef extern from`` block::
as "docstring" of a ``cdef extern from`` block:

cdef extern from *:
"""
/* This is C code which will be put
* in the .c file output by Cython */
static long square(long x) {return x * x;}
#define assign(x, y) ((x) = (y))
"""
long square(long x)
void assign(long& x, long y)
.. literalinclude:: ../../examples/userguide/external_C_code/c_code_docstring.pyx

The above is essentially equivalent to having the C code in a file
``header.h`` and writing ::
Expand Down

0 comments on commit 63b3b84

Please sign in to comment.