Hi, I'd appreciate help understanding why the below example fails. Thanks for
looking!
# test.nim
proc main =
let str = "hello"
var sptr = string.create(str.len)
#copyMem(sptr, unsafeAddr str, str.len) # this works
#sptr[] = str # this also works
# but let's try manual copy
for i in 0 ..< str.len:
sptr[][i] = str[i]
echo sptr[]
when isMainModule:
main()
Run
Output
Error: unhandled exception: index out of bounds, the container is empty
[IndexError]
Run
Nim 1.2.0, `nim c test.nim`
