Skip to content

Instantly share code, notes, and snippets.

@lujjjh

lujjjh/escape.go Secret

Created January 9, 2022 16:19
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 lujjjh/02d89fd848ee72ce3dd47156fc97c184 to your computer and use it in GitHub Desktop.
Save lujjjh/02d89fd848ee72ce3dd47156fc97c184 to your computer and use it in GitHub Desktop.
package main
//go:noinline
func foo() *int {
x := 42
return &x
}
func fooInline() *int {
x := 42
return &x
}
//go:noinline
func bar(p *int) {
*p = 42
}
func main() {
var s struct{}
println("sp:", &s)
println("foo:", foo())
println("fooInline:", fooInline())
q := new(int)
bar(q)
println("bar:", q)
}
/*
sp: 0xc000056758
foo: 0xc0000140b0
fooInline: 0xc000056758
bar: 0xc000056760
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment