Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow #8463 #14157 and document cstring literals modification is not allowed #15878

Merged
merged 14 commits into from
Nov 12, 2020
15 changes: 15 additions & 0 deletions doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,21 @@ string from a cstring:
var cstr: cstring = str
var newstr: string = $cstr

For the C backend, ``cstring`` literals shouldn't be modified.
ringabout marked this conversation as resolved.
Show resolved Hide resolved
ringabout marked this conversation as resolved.
Show resolved Hide resolved
Otherwise it will cause segmentation fault:
Araq marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: nim
var x = cstring"literals"
x[1] = 'A' # This is wrong!!!

If ``cstring`` originates from a regular memory(not read-only memory),
ringabout marked this conversation as resolved.
Show resolved Hide resolved
it could be modified:
Araq marked this conversation as resolved.
Show resolved Hide resolved

.. 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
Expand Down