Odin
Odin copied to clipboard
Global initializers not referenced fail to produce side-effects
package main
import "core:fmt"
a :: proc() -> int {
c = 32
return c
}
b :: proc() -> int {
return 64 / c
}
c: int
_a := a()
_b := b()
main :: proc() {
// Uncomment this line to avoid the SIGFPE.
// fmt.println(_a)
fmt.println(_b)
}
Because _a is not referenced, the call to a() never happens, thus never fulfilling the expected side-effects upon c, producing a division by zero.
If optimizations are enabled, this produces code which runs but outputs garbage on Linux AMD64.