How to map C string with length information?

@i11010520 Sorry for the confusion! This worked for me when I initialized a variable of type [*c]const u8 directly. But it doesn’t work when calling a function that returns [*c]const u8 and I have no idea why.

Anyway, calling sliceTo does work, as follows:

    const S = struct {
        pub fn demoString() [*c]const u8 {
            const str: []const u8  = "asdf";
            return str.ptr;
        }
    };
    const z_str: []const u8 = std.mem.sliceTo(S.demoString(), 0);
    try expectEqual(z_str.len, 4);

So it looks like you have to call sliceTo, which is not as nice, sorry about that, I should have tried it with a function call.

The following does work, which is why I said that the coercion would work directly. This is strange to me, but not relevant for your issue.

    const str: []const u8  = "asdf";
    const c_str: [*c]const u8 = str.ptr;
    const z_str: []const u8 = c_str;
    try expectEqual(z_str.len, 4);