( I am at the very beginning of programming in Zig and I am using Linux only. And I am no native English speaker…
The documentation I found on the internet regarding Zig always creates a slice from an array, which in turn was created from a string (for example…which meets my usecase…).
Is there a way to directly initialize a slice from a constant string and if “TRUE” - how can I do that?
Cheers!
Tuxic
EDIT/PS: I am using Zig compiled from HEAD/repo, updated daily…
No, []T (or []const T depending on constness) indicates a slice. An array needs a fixed size so you’d declare it with e.g. [5]u8, [_]u8 if the length can be inferred from its initialization.
Compare the language reference on Arrays and Slices.
Pretty much, though there was an error in my previous post (can’t const array child types, so it can be [N]T but not [N]const T) and inferring the length doesn’t work when assigning it from a string.
As you will see, the slice is a pointer to the same address as the array. The array has a storage size on the stack, the slice only stores the pointer to the actual data.