Skip to content

Instantly share code, notes, and snippets.

@samloeschen
Last active March 23, 2023 21:12
Show Gist options
  • Save samloeschen/2501258201ff6d24dbe177badcc53954 to your computer and use it in GitHub Desktop.
Save samloeschen/2501258201ff6d24dbe177badcc53954 to your computer and use it in GitHub Desktop.
odin M1 alignment error repro
package main
import "core:fmt"
DangerStruct :: struct {
guid: u128,
value: u64,
}
SafeStruct1 :: struct {
guidA: u64,
guidB: u64,
value: u64,
}
SafeStruct2 :: struct {
guid: u128,
valueA: u64,
valueB: u64,
}
main :: proc() {
// this list will have misaligned output when printed
listA := make([dynamic]DangerStruct)
for i in 0..<8 {
append(&listA, DangerStruct { u128(i), 0 })
}
fmt.println(listA)
fmt.println("\n=====================\n")
// this list will have correct output when printed
listB := make([dynamic]SafeStruct1)
for i in 0..<8 {
append(&listB, SafeStruct1 { u64(i), 0, 0 })
}
fmt.println(listB)
fmt.println("\n=====================\n")
// this list will also have correct output when printed
listC := make([dynamic]SafeStruct2)
for i in 0..<8 {
append(&listC, SafeStruct2 { u128(i), 0, 0 })
}
fmt.println(listC)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment