You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As Zig user who saw a link to this book, I randomly chose the string section. Just reading the first bit, I don't think this is a good introduction to the concept of working with text in Zig, but there's definitely a specific error:
A string object in Zig is an object of type []const u8, and, this object always contains two things: the same null-terminated array of bytes that you would find in a string literal value, plus a length value.
Nothing about the type []const u8 indicates that it will be null terminated. String literals are null terminated, but if that's a trait which is important to you (eg, c interopt), then you should be using a type which is actually null terminated such as [:0]u8.
Also, []const u8 doesn't contain an array, it contains a pointer to bytes. It having a pointer (and not the bytes themselves) is an important bit, but also as these bytes may come from any source (eg, an allocator) the pointer's destination may never have actually been a value of an array type.
The text was updated successfully, but these errors were encountered:
About the "[]const u8 is not a null-terminated array of bytes", you are right, this is clearly an error, therefore, I'm going to fix this.
Now, when you say:
I don't think this is a good introduction to the concept of working with text in Zig
Are you saying that the section "How strings work in Zig?" as a hole is not a good introduction? Or maybe you are saying just about the []const u8 thing? Anyway, this is a bit too broad for me to understand what you are thinking. Thus, it would be nice if you describe what specifically is not good, and give a suggestion of improvement maybe.
As Zig user who saw a link to this book, I randomly chose the string section. Just reading the first bit, I don't think this is a good introduction to the concept of working with text in Zig, but there's definitely a specific error:
Nothing about the type
[]const u8
indicates that it will be null terminated. String literals are null terminated, but if that's a trait which is important to you (eg, c interopt), then you should be using a type which is actually null terminated such as[:0]u8
.Also,
[]const u8
doesn't contain an array, it contains a pointer to bytes. It having a pointer (and not the bytes themselves) is an important bit, but also as these bytes may come from any source (eg, an allocator) the pointer's destination may never have actually been a value of an array type.The text was updated successfully, but these errors were encountered: