> @oswjk solution is correct.

It would be nice to have this in the standard library, so that one doesn't have 
to unleash `unsafeAddr` just to do a simple conversion. 😬

> openarray[byte] are not nul-terminated unlike strings and that would cause 
> issues if you are interfacing with C code that expect nul-terminated cstring.

I'm not. The problem is in pure Nim -- the cast returns a garbage `string` 
object, as shown in the above example.

It appears to be misinterpreting the raw bytes in the `openarray` as if they 
were a `string` object, so e.g. the string's length is the first bytes of the 
array interpreted as a little-endian int.

Again, I don't know the exact semantics of Nim's `cast[]`, so this might just 
be misuse of it. But it's dangerous that it works with one type (`seq`) but 
fails with a conceptually similar type.

Reply via email to