Skip to content

Instantly share code, notes, and snippets.

@apstndb
Created June 2, 2018 06:56
Show Gist options
  • Save apstndb/af22569a7aeb1b99d5170889675342d4 to your computer and use it in GitHub Desktop.
Save apstndb/af22569a7aeb1b99d5170889675342d4 to your computer and use it in GitHub Desktop.

https://twitter.com/sonatard/status/1002767157262872577

グローバル領域のポインタ比較は定数化されている。

$ go build -gcflags '-N -l' -o executable .
$ go tool objdump -s isEqual executable
TEXT main.isEqual(SB) /Users/apstndb/work/gosandbox/main.go
  main.go:7             0x10935b0               c644240800              MOVB $0x0, 0x8(SP)
  main.go:8             0x10935b5               c644240800              MOVB $0x0, 0x8(SP)
  main.go:8             0x10935ba               c3                      RET
  :-1                   0x10935bb               cc                      INT $0x3
  :-1                   0x10935bc               cc                      INT $0x3
  :-1                   0x10935bd               cc                      INT $0x3
  :-1                   0x10935be               cc                      INT $0x3
  :-1                   0x10935bf               cc                      INT $0x3
package main
import "fmt"
var a, b struct{}
func isEqual() bool {
return &a == &b
}
func main() {
fmt.Println(isEqual())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment