initial commit
This commit is contained in:
3
sizeofstring/go.mod
Normal file
3
sizeofstring/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module git.sunturtle.xyz/zephyr/errors-my-beloved/sizeofstring
|
||||
|
||||
go 1.25.0
|
13
sizeofstring/step1.go
Normal file
13
sizeofstring/step1.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build ignore
|
||||
|
||||
// step1.go
|
||||
package bocchi
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type Bocchi struct {
|
||||
x uint32
|
||||
y uint64
|
||||
}
|
||||
|
||||
var _ [0]struct{} = [unsafe.Sizeof(Bocchi{}) - 0]struct{}{}
|
13
sizeofstring/step2.go
Normal file
13
sizeofstring/step2.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build ignore
|
||||
|
||||
// step2.go
|
||||
package bocchi
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type Bocchi struct {
|
||||
x uint32
|
||||
y uint64
|
||||
}
|
||||
|
||||
var _ [0]struct{} = [unsafe.Sizeof(Bocchi{}) - 16]struct{}{}
|
18
sizeofstring/step3.go
Normal file
18
sizeofstring/step3.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package bocchi
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type Bocchi struct {
|
||||
x uint32
|
||||
y uint64
|
||||
}
|
||||
|
||||
// step3.go
|
||||
var (
|
||||
// assert Bocchi.x doesn't move
|
||||
_ [0]struct{} = [unsafe.Offsetof(Bocchi{}.x) - 0]struct{}{}
|
||||
// assert Bocchi.y comes next after Bocchi.x
|
||||
_ [0]struct{} = [unsafe.Offsetof(Bocchi{}.y) - (unsafe.Alignof(Bocchi{}.y))]struct{}{}
|
||||
// assert y is the last field in Bocchi
|
||||
_ [0]struct{} = [unsafe.Sizeof(Bocchi{}) - (unsafe.Alignof(Bocchi{}.y) + unsafe.Sizeof(Bocchi{}.y))]struct{}{}
|
||||
)
|
Reference in New Issue
Block a user