diff --git a/docs/src/userguide/external_C_code.rst b/docs/src/userguide/external_C_code.rst index bffe0aa917e41ec7210c67cf8ffdcb5065e6c910_ZG9jcy9zcmMvdXNlcmd1aWRlL2V4dGVybmFsX0NfY29kZS5yc3Q=..13d905a070eac57152624146f730652d76b7e1d3_ZG9jcy9zcmMvdXNlcmd1aWRlL2V4dGVybmFsX0NfY29kZS5yc3Q= 100644 --- a/docs/src/userguide/external_C_code.rst +++ b/docs/src/userguide/external_C_code.rst @@ -63,40 +63,6 @@ that you use. However, the Cython declarations don't always have to exactly match the C ones, and in some cases they shouldn't or can't. In particular: -1. Don't use ``const``. Cython doesn't know anything about ``const``, so just - leave it out. Most of the time this shouldn't cause any problem, although - on rare occasions you might have to use a cast. You can also explicitly - declare something like:: - - ctypedef char* const_char_ptr "const char*" - - though in most cases this will not be needed. - - .. warning:: - - A problem with const could arise if you have something like:: - - cdef extern from "grail.h": - char *nun - - where grail.h actually contains:: - - extern const char *nun; - - and you do:: - - cdef void languissement(char *s): - #something that doesn't change s - - ... - - languissement(nun) - - which will cause the C compiler to complain. You can work around it by - casting away the constness:: - - languissement(<char *>nun) - -2. Leave out any platform-specific extensions to C declarations such as +#. Leave out any platform-specific extensions to C declarations such as ``__declspec()``. @@ -101,6 +67,6 @@ ``__declspec()``. -3. If the header file declares a big struct and you only want to use a few +#. If the header file declares a big struct and you only want to use a few members, you only need to declare the members you're interested in. Leaving the rest out doesn't do any harm, because the C compiler will use the full definition from the header file. @@ -116,5 +82,4 @@ you can only do this inside a ``cdef extern from`` block; struct declarations anywhere else must be non-empty. - @@ -120,6 +85,5 @@ - -4. If the header file uses ``typedef`` names such as :c:type:`word` to refer +#. If the header file uses ``typedef`` names such as :c:type:`word` to refer to platform-dependent flavours of numeric types, you will need a corresponding :keyword:`ctypedef` statement, but you don't need to match the type exactly, just use something of the right general kind (int, float, @@ -131,6 +95,9 @@ file defines it correctly). Conversion to and from Python types, if any, will also be used for this new type. -5. If the header file uses macros to define constants, translate them into a - dummy :keyword:`enum` declaration. +#. If the header file uses macros to define constants, translate them into a + normal external variable declaration. You can also declare them as an + :keyword:`enum` if they contain normal :c:type:`int` values. Note that + Cython considers :keyword:`enum` to be equivalent to :c:type:`int`, so do + not do this for non-int values. @@ -136,4 +103,4 @@ -6. If the header file defines a function using a macro, declare it as though +#. If the header file defines a function using a macro, declare it as though it were an ordinary function, with appropriate argument and result types. @@ -138,6 +105,6 @@ it were an ordinary function, with appropriate argument and result types. -7. For archaic reasons C uses the keyword ``void`` to declare a function +#. For archaic reasons C uses the keyword ``void`` to declare a function taking no parameters. In Cython as in Python, simply declare such functions as :meth:`foo()`.