This is slightly misleading: the actual representation of OCaml strings in memory ensures that there is a NULL character just after the last character that is part of the string.
So as long as your string doesn’t contain other NULL characters (which you can check with caml_string_is_c_safe), you can cast it to a C string with the String_val macro.
1 Like