From 4663319bf566fc39df4252100d0e5d5f55da336e Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Thu, 12 Nov 2020 22:28:45 +0800 Subject: [PATCH] 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 Co-authored-by: Andreas Rumpf --- doc/manual.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index fa28582a74..bfcce24cf3 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