In demo.zig, after @cImport(@cInclude("demo.h")),
the auto-generated zig function declaration in cmport.zig file will be:
pub extern fn demoString() [*c]const u8;
Then, the result string in zig [*c]const u8 will lost the tail sentinel and length information.
Is there a way to keep the string length information without modifying the C code?
@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.
Fyi, the following works with the latest 0.10 code, but not with an older release I tried (0.9.0). So I may be stumbling on compiler changes in progress.
@JPL Thanks for your reminding!
Yes, after defining const str: []const u8 = "asdfé", the str.len is also 6.
Because .len is length of u8, not length of glyph.