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
Gwenaël Samain
cython
Commits
c977cbda
Commit
c977cbda
authored
Jun 29, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clarification in 'const char*' doc section
parent
daeebebb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
5 deletions
+16
-5
docs/src/tutorial/strings.rst
docs/src/tutorial/strings.rst
+16
-5
No files found.
docs/src/tutorial/strings.rst
View file @
c977cbda
...
...
@@ -84,6 +84,7 @@ not modify a string they return, for example:
.. code-block:: c
typedef const char specialChar;
int process_string(const char* s);
const unsigned char* look_up_cached_string(const unsigned char* key);
...
...
@@ -94,19 +95,29 @@ at a textual level.
In general, for arguments of external C functions, the ``const``
modifier does not matter and can be left out in the Cython
declaration (e.g. in a .pxd file). The C compiler will still do
the right thing
.
the right thing
, even if you declare this to Cython::
However, in most other situations, e.g. for return values and
specifically typedef-ed API types, it does matter and the C compiler
will emit a warning if used incorrectly. To help with this, you can
use the type definitions in the ``libc.string`` module, e.g.::
cdef extern from "someheader.h":
int process_string(char* s) # note: looses API information!
However, in most other situations, such as for return values and
variables that use specifically typedef-ed API types, it does matter
and the C compiler will emit a warning if used incorrectly. To help
with this, you can use the type definitions in the ``libc.string``
module, e.g.::
from libc.string cimport const_char, const_uchar
cdef extern from "someheader.h":
ctypedef const_char specialChar
int process_string(const_char* s)
const_uchar* look_up_cached_string(const_uchar* key)
Note: even if the API only uses ``const`` for function arguments,
it is still preferable to properly declare them using the
:c:type:`const_char` types in order to simplify adaptations, e.g.
if Cython ever gains language support for ``const``.
Decoding bytes to text
----------------------
...
...
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