Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Global initializers not referenced fail to produce side-effects

Open Feoramund opened this issue 4 months ago • 3 comments

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.

Feoramund avatar Jun 14 '25 21:06 Feoramund