Casting to a C array of strings

Zig’s null-terminated array initiating does NOT need the last null. Zig’s null-terminated array’s len field (my_array.len) will return the same len as how many “actual” items you have, and will not include the last null. So you don’t do anything with last null in your codes… The compiler will do the job for you. See here: https://ziglang.org/documentation/master/#Sentinel-Terminated-Arrays

This should work:

const string_list = [_:null]?[*:0]const u8 {"foo", "bar"};
const list = string_hungy_func(&string_list);

I had a similar discussion another day here: https://ziggit.dev/t/how-to-handle-c-const-c-const-u8-in-a-c-library/8768

1 Like