Created
November 17, 2017 21:40
-
-
Save jfo/798a7cb66ae782f770e682cc0d37c852 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const warn = @import("std").debug.warn; | |
fn dangle1() -> &u8 { | |
var x: u8 = 5; | |
&x | |
} | |
fn dangle2() -> &u8 { | |
var x: u8 = 5; | |
const y: &u8 = &x; | |
y | |
} | |
test "ohhh noooooo" { | |
// yassssssss ty | |
/// error: function returns address of local variable | |
_ = dangle1(); | |
// nej tak | |
/// ohhhh noooooooo! | |
const shittypointer = dangle2(); | |
warn("{}", *shittypointer); // ¯\_(ツ)_/¯ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment