Is the order of function argument evaluation stable?

So I’m just watching https://www.youtube.com/watch?v=69pvUyBsruQ&t=2h15m19s and Simon Carter is referencing a difference between C compilers / platforms in the order of evaluating function arguments. So this makes me wonder:

Is this order defined in Zig? Is the following guaranteed?

functionCall(evaluatedFirst(), evaluatedSecond());

See also:

1 Like
2 Likes

Thanks. That’s related, but does not seem to address the evaluation order of function arguments.

For instance, C’s comma operator , is defined as a sequence point

I did a quick search - “comma operator” is not referring to the comma used for delimiting function arguments.

The part about the comma operator is talking about C, I think this part is more relevant:

7 Likes

I’m fairly sure it’s well defined to evaluate left-to-right. (But I didn’t find it in a quick search in the language reference, so could be wrong)

Your post reminded me to look at this issue regarding the evaluation order of operators like += etc: Proposal: Load `lhs` after `rhs` is executed for assignment operators like `+=` · Issue #25315 · ziglang/zig · GitHub

… which is surprisingly non-obvious.

Considering field initialization order in zig is well defined, it would make sense function argument evaluation order would be too, considering @call is a thing and accepts args as tuple.
I hope the langref makes it clear at some point.

1 Like