That’s a very convoluted way to express a simple requiremente: I want the bytes without an additional terminator.
Rust handles the distinction between those two types quite well one for ordinary string literals and another for C literals; I think Zig should benefit from a similar way and offer more control and explicitness in that regard, rather than storing an extra byte “just in case.”
const text = "test";
“test” has type *const [N:0]u8, which is a literal backed by four content bytes + a traling zero
I know we can quit that terminator using an array conversion or a comptime helper, etc.
But requesting a N bytes backing array should be similarly and so easy, concise and explicit.
The saving can be small for just one literal, but it can accumulate with many literals and matter in memory-constrained programs. Making this choice easier would fit Zig’s philosophy on explicitness and control over memory representation.
I can understand the convenience for C interoperability however i dont think that matter should dictate the default representation of Zig’s literals and in some aspects of the language. I would prefer ordinary literals without an implicit terminator with simple explicit way to construct a version with terminator when an interface requires one.
For literals knwon at compile time, this choice could be resolved during compilation.
Also interfaces requiring only a pointer and a length would not need additional terminator in the literal’s underlying storage.