We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
0.10.1
The following code
const std = @import("std"); const print = std.debug.print; fn foo() fn() *u32 { const T = struct { fn bar() *u32 { var x: u32 = 123; return &x; } }; return T.bar; } pub fn main() void { print("Result: {}", .{foo()().*}); }
gives different outputs with different build flags. It prints Result: 123 for
zig build-exe example.zig & example.exe
and Result: 00 for
zig build-exe example.zig -O ReleaseSafe & example.exe
It works for me locally also on godbolt:
I expected to have the same output, or the program to panic at runtime, or to not to compile at all.
The text was updated successfully, but these errors were encountered:
I have no idea about the expected behaviour, but this smells bad.
The code is from the ziggit.dev thread https://ziggit.dev/t/how-to-declare-local-functions-in-functions/1234/
Sorry, something went wrong.
Dereferencing a pointer to the stack variable x after bar() has returned is illegal behavior.
x
bar()
See #2646 and #2301
No branches or pull requests
Zig Version
0.10.1
Steps to Reproduce and Observed Behavior
The following code
gives different outputs with different build flags. It prints Result: 123 for
and Result: 00 for
It works for me locally also on godbolt:
Expected Behavior
I expected to have the same output, or the program to panic at runtime, or to not to compile at all.
The text was updated successfully, but these errors were encountered: