var x: [*:null]?[*:0]const u8 = undefined;
lib.foo(&x);
error: expected type '[*c][*c]u8', found '[*:null]?[*:0]const u8
I think the issue is that in the other thread, the user was working with an array of strings, whereas in this case, the foo function just populates a single string.
$ zig build run
Segmentation fault at address 0x0
???:?:?: 0x7ffff7e72075 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7ffff7e72075` was not available, trace may be incomplete
I ran into this recently too. The issue is that if x: ?*[*:0]u8 was allowed to coerce to y: [*c][*c]u8 = x, then the type system would have to allow y.* = null, violating the guarantee that x.?.* is not null. So you have to add an extra optional x: ?*?[*:0]u8.
It seems that this is a limitation you have to live with when using @cImport, and to get the “correct” types you need to manually declare the signature of foo (which I generally prefer over @cImport anyway).