Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posts/learning-zig-day-2/ #45

Open
utterances-bot opened this issue May 17, 2021 · 2 comments
Open

posts/learning-zig-day-2/ #45

utterances-bot opened this issue May 17, 2021 · 2 comments

Comments

@utterances-bot
Copy link

Learning Zig - Day 2 - Harsh Shandilya

Onwards in our quest to learn Zig

https://msfjarvis.dev/posts/learning-zig-day-2/

Copy link

komuw commented May 17, 2021

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 }

see: https://zig.godbolt.org/z/68fecP567

@msfjarvis
Copy link
Owner

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 }

see: zig.godbolt.org/z/68fecP567

I suppose that's what I get for trying to use the stable branch. Will make the switch to nightly, thanks for the tip!

msfjarvis pushed a commit that referenced this issue Apr 1, 2024
Include front matter in home and list pages if provided
msfjarvis pushed a commit that referenced this issue Apr 1, 2024
Include front matter in home and list pages if provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants