Does Zig make any expression evaluation order guarantees?

For example, is the following program guaranteed to print 0 1 1.
In Go, there are not such guarantees.

const std = @import("std");

const T = struct {
	x: u32,
	
	fn inc(t: *@This()) u32 {
		t.x += 1;
		return t.x;
	}
};

pub fn main() void {
	var t = T{.x = 0};
	std.debug.print("{} {} {}\n", .{t.x, t.inc(), t.x});
	// 0 1 1
}

It’s not codified in the language reference, but yes as far as I can tell.

Related: Do struct field initializations occur in well defined order?

1 Like

It is great if this is guaranteed.

I’m scared to ask, but what does Go do that means it cannot guarantee the order?

If you are interested

2 Likes