by acqq · 6y ago · 0 comments
std/debug.zig:
pub fn print(comptime fmt: []const u8, args: anytype) void {
const held = stderr_mutex.acquire();
defer held.release();
const stderr = io.getStdErr().writer();
nosuspend stderr.print(fmt, args) catch return;
}
io/writer.zig: pub fn print(self: Self, comptime format: []const u8, args: anytype) Error!void {
return std.fmt.format(self, format, args);
}
std/fmt.zig: pub fn format(
writer: anytype,
comptime fmt: []const u8,
args: anytype,
) !void {
...
It's all based on the language features and the actual implementations of zig's standard library code, and at least I don't see anything "wrapped" there, and nothing what C++, C or asm programmers understand as "a macro".I didn't actually check the zig std source. I was referring to what I was seeing in radare2 :)
https://ziglang.org/documentation/master/#comptime
See an example calling firstNPrimes. "When we compile this program, Zig generates the constants with the answer pre-computed." "Note that we did not have to do anything special with the syntax of these functions. For example, we could call the sum function as is with a slice of numbers whose length and values were only known at run-time."
Then see "Case Study: printf in Zig"