Is Julia `String` NUL-terminated?

Viewed 67

Is it safe to directly pass "abc" to a ccall that expects a Ptr{Cchar}?

I know I can use Cstring in the ccall instead, this question is more about the String type itself.

1 Answers

Yes, currently Strings in Julia are always NUL-terminated. This is intentionally not documented though, since it might change in future versions of Julia. That's why you should generally prefer to use Cstring explicitly whenever something expects a NUL-terminated string. This is currently just a no-op, but it should be more future-proof and I also find it more self-documenting.

Related