#string literal defaults to sentinel
1 messages · Page 1 of 1 (latest)
slices are already pointers so that type is a pointer to a pointer
@as([]u8, "test"); also fails
that can coerce to [:0]const u8 or []const u8
[]u8 is not constant
var string: []u8 = "test"; doesnt work either, sorry for this nooby questions
i cant seem to get my head around it
"test" is a pointer to immutable data stored in your program's executable
oh. that makes sense
you can't turn it into any non-const pointer type because the data itself cannot be modified
what you could do is var string = "test".* which will copy the array that "test" points to into a different one which is mutable
string there will be a [4:0]u8 (not a pointer)
im trying to right a parser and this is the function
pub fn parse(ally: Allocator, string: *const []u8) !Sequence {...}```
*const []u8 gives me information to the length and ptr, so why cant i use it?
*const []u8 is a constant pointer to a mutable string
like a double pointer cuz the string itself is a pointer
if you want an immutable string just use []const u8
but i thought []u8 is not a pointer? its data
and when i use []const u8 as a parameter the compiler wants everything to become comptime, so im guessing it is the case
slice is ptr + len https://ziglang.org/documentation/0.13.0/#Slices
[]T (slice) is pointer, [n]T (array) is value
ah so that was it, thats what was confusing me thank you,
and here the compiler just inferred the type of an int as comptime_int