My code is calling the jack API. The function jack_get_ports
is giving me a headache. The documentation says this function returns a null terminated array of ports (actually the port’s names).
This is the function’s signature generated by @cImport
.
pub extern fn jack_get_ports(client: ?*jack_client_t, port_name_pattern: [*c]const u8, type_name_pattern: [*c]const u8, flags: c_ulong) [*c][*c]const u8;
Apparently cImport
missed the null terminated part ?
const ports = c.jack_get_ports(self.client, "", "", c.JackPortIsPhysical | c.JackPortIsOutput);
for (ports) |p| {
_ = p;
}
This won’t compile because ports has no upper bound - I guess that’s because the null terminated part is missing from the type declaration.
So, should I coerce it to the actual type ? Is it [*:0][*c]const u8
? I must admit I’m a bit lost with pointer juggling here …
const ports = c.jack_get_ports(self.client, "", "", c.JackPortIsPhysical | c.JackPortIsOutput);
const ports_coerced = @as([*:0][*c]const u8, ports);
for (ports_coerced) |p| {
_ = p;
}
this compiles but I get the same “no upper bound” error.