Commit 679eff3e authored by Stefan Behnel's avatar Stefan Behnel

Add a more common and more versatile example to the Verbatim C-Code documentation.

parent 474573b3
cdef extern from *:
"""
#if defined(WIN32) || defined(MS_WINDOWS)
#include "windows.h"
#define myapp_sleep(m) Sleep(m)
#else
#include <unistd.h>
#define myapp_sleep(m) ((void) usleep((m) * 1000))
#endif
"""
# using "myapp_" prefix in the C code to prevent C naming conflicts
void msleep "myapp_sleep"(int milliseconds) nogil
msleep(milliseconds=1)
......@@ -335,7 +335,7 @@ Including verbatim C code
For advanced use cases, Cython allows you to directly write C code
as "docstring" of a ``cdef extern from`` block:
.. literalinclude:: ../../examples/userguide/external_C_code/c_code_docstring.pyx
.. literalinclude:: ../../examples/userguide/external_C_code/verbatim_c_code.pyx
The above is essentially equivalent to having the C code in a file
``header.h`` and writing ::
......@@ -344,6 +344,11 @@ The above is essentially equivalent to having the C code in a file
long square(long x)
void assign(long& x, long y)
This feature is commonly used for platform specific adaptations at
compile time, for example::
.. literalinclude:: ../../examples/userguide/external_C_code/platform_adaptation.pyx
It is also possible to combine a header file and verbatim C code::
cdef extern from "badheader.h":
......
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