Last active
December 18, 2024 15:15
-
-
Save up1/69a6749df9464f15743dbb1a0c711762 to your computer and use it in GitHub Desktop.
Go :: fieldalignment
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
$go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest | |
$fieldalignment -fix <package or filename> | |
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
// Before | |
func main() { | |
type first struct { | |
f float64 | |
i int32 | |
b bool | |
} | |
a := first{} | |
fmt.Println(unsafe.Sizeof(a)) // 24 bytes | |
} | |
$fieldalignment -fix demo.go | |
demo.go:9:13: struct of size 24 could be 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment