Skip to content

Commit

Permalink
follow nim-lang#8463 nim-lang#14157 and document cstring literals
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Nov 7, 2020
1 parent fa5f225 commit 2ad6b96
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,13 @@ string from a cstring:
var cstr: cstring = str
var newstr: string = $cstr
You shouldn't modify cstring literals. Otherwise unexpected situations may happen.

This comment has been minimized.

Copy link
@timotheecour

timotheecour Nov 7, 2020

need to clarify that it's ok to write to a cstring if you know it originates from a regular memory location, eg:
var a = "foo"
var b: cstring = a
b[0] = 'F' # ok


.. code-block:: nim

This comment has been minimized.

Copy link
@timotheecour

timotheecour Nov 7, 2020

unexpected situations

I'm not sure it's UB. Can we make a stronger statement? eg guaranteed program crash (at least on OSX, giving SIGBUS; probably other OS too)

# this is wrong!!!
var x = cstring"literals"
x[1] = 'A'
Structured types
----------------
A variable of a structured type can hold multiple values at the same
Expand Down

0 comments on commit 2ad6b96

Please sign in to comment.