Hello,
I am trying out Zig for the first time. It is exciting to discover a
modern language with first-class support for no standard library.
I was trying to build a small hello world program following the
(apparently now outdated) instructions here:
https://drewdevault.com/2020/01/04/Slow.html#testzig
I figured out that the command should probably be changed to the following:
./zig build-exe -O ReleaseSmall -fstrip hello.zig
However, this generates a compile time error:
hello.zig:4:43: error: expected error union type, found 'fs.file.File'
const stdout = try std.io.getStdOut();
Can anyone provide updated source code so that the example will compile?
For reference, here is the original (outdated) source code:
const std = @import("std");
pub fn main() !void {
const stdout = try std.io.getStdOut();
try stdout.write("hello world\n");
}
Thank you!
Parke
On 8/21/23 15:22, Parke wrote:
> Hello,
>
> I am trying out Zig for the first time. It is exciting to discover a
> modern language with first-class support for no standard library.
>
> I was trying to build a small hello world program following the
> (apparently now outdated) instructions here:
>
> https://drewdevault.com/2020/01/04/Slow.html#testzig
>
> I figured out that the command should probably be changed to the following:
>
> ./zig build-exe -O ReleaseSmall -fstrip hello.zig
>
> However, this generates a compile time error:
>
> hello.zig:4:43: error: expected error union type, found 'fs.file.File'
> const stdout = try std.io.getStdOut();
>
> Can anyone provide updated source code so that the example will compile?
1. getStdOut no longer fails; remove `try`
2. change `write` to `writeAll`
I updated the sample below for you:
>
> For reference, here is the original (outdated) source code:
>
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut();
try stdout.writeAll("hello world\n");
}
>
> Thank you!
>
> Parke
Happy hacking!
Andrew