var s = newString(1024)
Run
That creates a buffer of 1025 characters, but only 1024 are legally accessible.
I.e.
s[1024] = 'Z'
Run
is an error:
Error: unhandled exception: index 1024 not in 0 .. 1023 [IndexDefect]
Run
It's an important distinction when interacting with C-code because many C
functions want to read/write that final 0 (using "char*" i.e. "cstring), while
Nim will write it implicitly at the end of a "string".
That means you (usually) can and should add 1 to "len" when telling C the
buffer size, e.g.
snprintf(s.cstring, 1025, "Foo bar %s", "Hello");
Run