≈ the.bay.news

Assigning void returned from function?

Ziggit
Assigning void returned from function?
Why does this compile? const std = @import("std"); pub fn main() !void { const foo = std.debug.print("Hello, world\n", .{}); _ = foo; } std.debug.print() returns void, but Zig doesn’t complain if I try to assign it to foo. This came up for me in a project I’m working on, where I mistakenly assumed some API in a third-party lib was returning a value when in fact it wasn’t. I later triggered a compiler error by trying to format the returned value into a string with {s}, but it took me ...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.