summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2020-11-12 22:28:45 +0800
committerGitHub <noreply@github.com>2020-11-12 15:28:45 +0100
commit4663319bf566fc39df4252100d0e5d5f55da336e (patch)
treeb63e6b3e2813e1ae3d2e03d8ffcd33c02340071d
parentcc882917feda383a283eb128f80bf49681921995 (diff)
downloadNim-4663319bf566fc39df4252100d0e5d5f55da336e.tar.gz
follow #8463 #14157 and document cstring literals modification is not allowed (#15878)
* follow #8463 #14157 and document cstring literals
* Update doc/manual.rst

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r--doc/manual.rst14
1 files changed, 14 insertions, 0 deletions
diff --git a/doc/manual.rst b/doc/manual.rst
index fa28582a7..bfcce24cf 100644
--- a/doc/manual.rst
+++ b/doc/manual.rst
@@ -1280,6 +1280,20 @@ string from a cstring:
   var cstr: cstring = str
   var newstr: string = $cstr
 
+``cstring`` literals shouldn't be modified.
+
+.. code-block:: nim
+  var x = cstring"literals"
+  x[1] = 'A' # This is wrong!!!
+
+If the ``cstring`` originates from a regular memory (not read-only memory),
+it can be modified:
+
+.. code-block:: nim
+  var x = "123456"
+  var s: cstring = x
+  s[0] = 'u' # This is ok
+
 Structured types
 ----------------
 A variable of a structured type can hold multiple values at the same