diff options
author | Matus Valo <matusvalo@users.noreply.github.com> | 2022-12-11 15:05:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-11 14:05:04 +0000 |
commit | f109a57212c5078757b0ea0f847f01b86eb19912 (patch) | |
tree | c63ede7bf1d84ca23ae8e96205aec725a2061551 | |
parent | 39ee651a45e45e31805aa94d5c119f0283637f94 (diff) | |
download | cython-f109a57212c5078757b0ea0f847f01b86eb19912.tar.gz |
Docs: Document type qualifiers (#5165)
-rw-r--r-- | docs/src/userguide/language_basics.rst | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/docs/src/userguide/language_basics.rst b/docs/src/userguide/language_basics.rst index ff7007760..191cb32b2 100644 --- a/docs/src/userguide/language_basics.rst +++ b/docs/src/userguide/language_basics.rst @@ -317,6 +317,34 @@ and is typically what one wants). If you want to use these numeric Python types simply omit the type declaration and let them be objects. + +Type qualifiers +--------------- + +Cython supports ``const`` and ``volatile`` `C type qualifiers <https://en.wikipedia.org/wiki/Type_qualifier>`_:: + + cdef volatile int i = 5 + + cdef const int sum(const int a, const int b): + return a + b + + cdef void print_const_pointer(const int *value): + print(value[0]) + + cdef void print_pointer_to_const_value(int * const value): + print(value[0]) + + cdef void print_const_pointer_to_const_value(const int * const value): + print(value[0]) + +.. Note:: + + Both type qualifiers are not supported by pure python mode. Moreover, the ``const`` modifier is unusable + in a lot of contexts since Cython needs to generate definitions and their assignments separately. Therefore + we suggest using it mainly for function argument and pointer types where ``const`` is necessary to + work with an existing C/C++ interface. + + Extension Types --------------- |