https://kotlinlang.org logo
Title
l

Landry Norris

01/26/2023, 3:43 PM
I was under the impression that
String#encodeToByteArray
would add a null terminator, since it’s used by cstr, however, this does not appear to be the case. Should I manually add
0.toChar()
to each string I need to pass to C? I also noticed that ‘\0’ is not valid in Kotlin, saying it’s an illegal escape.
Looks like cstr adds 1 to the size when placing and manually sets the last byte, after writing the result of encodeToByteArray.
e

ephemient

01/26/2023, 5:45 PM
Kotlin doesn't have octal escapes, only hex unicode escapes (and a few named escapes). NUL char is
\u0000