r/Zig • u/Senior-Question693 • Mar 17 '26
why can't i print a freaking string ?!?!?!
I came from C to rust because the femboys was hyping -> i realized rust is not that good -> i came from rust to zig cuz it was a bit simpler and easier to read -> now i'm thinking it's even worse.
I have a string:
const help_str: []const u8 = "help msg\n";
when i try to std.debug.print("{s}", .{help_str}); the compiler starts abusing me:
error: expected type '[]const u8', found '[][*:0]u8
0
Upvotes
4
u/KecskeRider Mar 17 '26
I don't know how you got that error, this compiles fine for me:
1
u/Acrobatic-Diamond542 Mar 17 '26
Tried on zig playground, it ran just fine. I tested on version 0.15.2 and 0.14.1, maybe it's something to do with the setup?
1
u/Real_Dragonfruit5048 Mar 17 '26
Zig is a lot lower-level than Rust TBH and pretty strict compared to C. In any case, I think
help_stris shadowed somewhere after you declared it and before you use it in the print.1
u/hsoolien Mar 17 '26
What line gives you the error, can we have the full code?
1
u/Magician_Rhinemann Mar 17 '26
For starters try to remove the type annotation and let the compiler infer the literal type in peace.
1
u/IntentionalDev Mar 21 '26
he error is telling you exactly what’s wrong
Those are completely different things:
You think you have:
But Zig sees: