Created
October 18, 2018 19:22
-
-
Save felixge/6ae41cece4b8b9755d1b06ab1740b7ff 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
package main | |
import "fmt" | |
func main() { | |
f1 := &Foo{} | |
f2 := &Foo{} | |
fmt.Printf("%p = %p\n", f1, f2) | |
b1 := &Bar{} | |
b2 := &Bar{} | |
fmt.Printf("%p != %p\n", b1, b2) | |
} | |
type Foo struct{} | |
type Bar struct{ Field string } |
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
$ go run main.go | |
0x1157c08 = 0x1157c08 | |
0xc42000e1e0 != 0xc42000e1f0 | |
WTH? Why wouldn't the pointers be different in both cases? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mholt yeah, the spec seems to leave it open to the implementation. The latter seems to return a single fixed address for all 0-sized allocations:
See: