initial commit

This commit is contained in:
2025-08-27 08:48:19 -04:00
commit 85bac6b12b
25 changed files with 570 additions and 0 deletions

3
sizeofstring/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module git.sunturtle.xyz/zephyr/errors-my-beloved/sizeofstring
go 1.25.0

13
sizeofstring/step1.go Normal file
View 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
View 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
View 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{}{}
)