$ make diff
cat -n 1.go
1 package main
2
3 import "fmt"
4
5 func main() {
6 a := [5]int{}
7 b := a[:]
8 fmt.Println(b)
9 }
go build -trimpath -o 1 ./1.go
go tool objdump -gnu -s main.main 1 | sed 's/1.go//g' | cut -f2- > 1.dump
cat -n 2.go
1 package main
2
3 import "fmt"
4
5 func main() {
6 a := (&[5]int{})[:]
7 fmt.Println(a)
8 }
go build -trimpath -o 2 ./2.go
go tool objdump -gnu -s main.main 2 | sed 's/2.go//g' | cut -f2- > 2.dump
diff 1.dump 2.dump
-
-
Save takumakei/b265985f18ff5465a98cf9aedb8af7e2 to your computer and use it in GitHub Desktop.
Goの(&[5]int{})[:]の実験
This file contains hidden or 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() { | |
a := [5]int{} | |
b := a[:] | |
fmt.Println(b) | |
} |
This file contains hidden or 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() { | |
a := (&[5]int{})[:] | |
fmt.Println(a) | |
} |
This file contains hidden or 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
.DEFAULT_GOAL := help | |
.PHONY: help diff | |
help: ## show this message | |
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-8s\033[0m %s\n", $$1, $$2}' | |
diff: ## 1 と 2 の go tool objdump の差分を表示する | |
diff: 1.dump 2.dump | |
diff $^ | |
1.dump: 1 | |
go tool objdump -gnu -s main.main 1 | sed 's/1.go/0.go/g' | cut -f2- > 1.dump | |
2.dump: 2 | |
go tool objdump -gnu -s main.main 2 | sed 's/2.go/0.go/g' | cut -f2- > 2.dump | |
1: | |
cat -n 1.go | |
go build -trimpath -o 1 ./1.go | |
2: | |
cat -n 2.go | |
go build -trimpath -o 2 ./2.go | |
clean: ## clean | |
-rm 1 2 1.dump 2.dump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment