Open utterances-bot opened 3 years ago
The only problem I encountered here was that I can’t figure out how to print an array!
If you try;
const std = @import("std");
pub fn main() void {
const implicitly_sized_array = [_]u8{0, 1, 2, 3};
std.debug.print("This is an array: {}\n", .{implicitly_sized_array});
}
on master branch, you get a helpful compiler error:
error: cannot format array without a specifier (i.e. {s} or {any})
@compileError("cannot format array without a specifier (i.e. {s} or {any})");
^
so when we change our code to;
std.debug.print("This is an array: {any}\n", .{implicitly_sized_array});
we get;
This is an array: { 0, 1, 2, 3 }
The only problem I encountered here was that I can’t figure out how to print an array!
If you try;
const std = @import("std"); pub fn main() void { const implicitly_sized_array = [_]u8{0, 1, 2, 3}; std.debug.print("This is an array: {}\n", .{implicitly_sized_array}); }
on master branch, you get a helpful compiler error:
error: cannot format array without a specifier (i.e. {s} or {any}) @compileError("cannot format array without a specifier (i.e. {s} or {any})"); ^
so when we change our code to;
std.debug.print("This is an array: {any}\n", .{implicitly_sized_array});
we get;
This is an array: { 0, 1, 2, 3 }
I suppose that's what I get for trying to use the stable branch. Will make the switch to nightly, thanks for the tip!
Learning Zig - Day 2 - Harsh Shandilya
Onwards in our quest to learn Zig
https://msfjarvis.dev/posts/learning-zig-day-2/