Last active
March 23, 2023 21:12
-
-
Save samloeschen/2501258201ff6d24dbe177badcc53954 to your computer and use it in GitHub Desktop.
odin M1 alignment error repro
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 "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