Skip to content

Instantly share code, notes, and snippets.

@Sahnvour
Last active March 3, 2019 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sahnvour/abf000581b3958882d3f493012f030f9 to your computer and use it in GitHub Desktop.
Save Sahnvour/abf000581b3958882d3f493012f030f9 to your computer and use it in GitHub Desktop.
$ zig run returnaddress.zig
u8@7ff6c887f03f log from foo
reached unreachable code
D:\DEV\Zig\test\returnaddress.zig:5:5: 0x7ff6c887f250 in log (run.obj)
unreachable;
^
D:\DEV\Zig\test\returnaddress.zig:15:12: 0x7ff6c887f03f in bar (run.obj)
return @inlineCall(foo, n);
^
D:\DEV\Zig\test\returnaddress.zig:19:21: 0x7ff6c887f004 in main (run.obj)
warn("{}\n", bar(13));
^
D:\DEV\Install\zig\lib\zig\std\special\bootstrap.zig:51:40: 0x7ff6c887efe3 in ??? (run.obj)
std.os.windows.ExitProcess(callMain());
^
???:?:?: 0x7ffb24fa3dc4 in ??? (???)
???:?:?: 0x7ffb27223691 in ??? (???)
const warn = @import("std").debug.warn;
fn log(msg: []const u8) void {
warn("{} {}\n", @returnAddress(), msg);
unreachable;
}
fn foo(n: u32) u32 {
@noInlineCall(log, "log from foo");
return n * 2;
}
fn bar(n: u32) u32 {
return @inlineCall(foo, n);
}
pub fn main() void {
warn("{}\n", bar(13));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment